練習 - 測試您的新虛擬機器

已完成

當您建立虛擬機器時,您會為其指派可透過因特網連線的公用 IP 位址,以及 Azure 資料中心內使用的私人 IP 位址。 這兩個值都會出現在命令傳回的 JSON 區塊 create 中,如下所示:

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

注意

此練習為選擇性項目。 如果您想要完成此練習,您必須先建立 Azure 訂用帳戶,才能開始。 如果您沒有 Azure 帳戶,或目前不想建立帳戶,您可以閱讀指示,以便瞭解所呈現的資訊。

注意

在本單元中,您會使用 Azure Cloud Shell 作為終端機。 您可以透過 Azure 入口網站Cloud Shell 登入來存取 Cloud Shell。 您無需在 PC 或筆記本電腦上安裝任何東西即可使用它。

使用 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 來登出虛擬機器。