练习 - 测试新虚拟机

已完成

创建虚拟机时,请为其分配可通过 Internet 访问的公共 IP 地址和 Azure 数据中心中使用的专用 IP 地址。 这两个值都显示在 create 命令返回的 JSON 块中,如下所示:

{
   ...
  "privateIpAddress": "10.0.0.4",
  "publicIpAddress": "40.83.165.85",
   ...
}

注意

本练习可选做。 若要完成本练习,则需要在开始之前创建 Azure 订阅。 如果没有 Azure 帐户或不想暂时创建一个帐户,可以通读说明,以便了解所显示的信息。

注意

在本单元中,你将使用 Azure Cloud Shell 作为终端。 可以通过 Azure 门户Cloud Shell 登录访问 Cloud Shell。 无需在电脑或笔记本电脑上安装任何内容即可使用它。

使用 SSH 连接到 VM

通过使用安全外壳 (ssh) 工具中的公共 IP 地址,我们可以快速测试 Linux VM 是否已启动并正在运行。 请记住,由于我们将管理员名称设置为 azureuser,因此必须对此进行指定。 请务必使用你正在运行的实例的公共 IP 地址。

ssh azureuser@<public-ip-address>

注意

我们不需要密码,因为我们在 VM 创建过程中生成了 SSH 密钥对。 首次进入 VM 时,你会收到有关验证主机的提示。

这是因为我们正尝试直接访问 IP 地址,而不是通过主机名访问。 回答“是”会将 IP 地址保存为用于连接的有效主机,并允许继续建立连接

The authenticity of host '40.83.165.85 (40.83.165.85)' can't be established.
RSA key fingerprint is SHA256:hlFnTCAzgWVFiMxHK194I2ap6+5hZoj9ex8+/hoM7rE.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '40.83.165.85' (RSA) to the list of known hosts.

然后,会显示一个远程 shell,可在其中输入 Linux 命令。

Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 5.0.0-1014-azure x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Wed Aug 21 20:32:04 UTC 2019

  System load:  0.0               Processes:           108
  Usage of /:   4.2% of 28.90GB   Users logged in:     0
  Memory usage: 9%                IP address for eth0: 10.0.0.5
  Swap usage:   0%

0 packages can be updated.
0 updates are security updates.

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

azureuser@SampleVM:~$

尝试一些命令(如 psls)作为练习。 完成后,键入 exitlogout 以注销虚拟机。