SSH 公開キーを作成
シェルコマンドで公開キーを作成します。
私の場合は、「Git for Windows」( https://gitforwindows.org )についてくる「Git Bash」を使用しました。
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key : (ここに任意の名前)
Enter passphrase (empty for no passphrase): (ここに任意のパスワード)
Enter same passphrase again: ( パスワードを再入力 )
Your identification has been saved in {入力した名前}.
Your public key has been saved in {入力した名前}.pub.
これで、入力した名前で、秘密鍵ファイルと公開鍵ファイルが作成されます。.pubの拡張子がつくのが公開鍵です。
私の場合は、名前に「azure_playground_id_rsa」と入力したので、以下の2ファイルが作成されました。
・azure_playground_id_rsa
・azure_playground_id_rsa.pub
ここで設定したパスワードは忘れないようにしましょう。
AzureVMを作成
azureのポータル( https://portal.azure.com )からVMを作成します。
地域
最寄りの拠点を選択しました。イメージ
ubuntuの新しいほうを選択しました。サイズ
試しに作ってみるだけなので、最少の構成にしました。認証の種類
SSH 公開キーで接続したいので、それを選択。ユーザー名
管理者アカウント名を入力します。SSH 公開キー
上で作成した公開鍵ファイルの内容(テキスト)をコピー&ペーストします。パブリック受信ポート
SSH接続をしたいので、「選択したポートを許可する」を選びます。受信ポートを選択
SSH接続したいので、「SSH」を選択します。
最後に、「確認および作成」ボタンをクリックします。
確認画面が表示されるので、そこで作成を確定します。
AzureVMのipアドレス確認
azureのポータルの「Virtual Machines」画面より、VMのipアドレスを確認します。
一覧の末尾、「…」をクリックするとサブメニューが表示されるので、そこで「接続」を選択するとipアドレスを確認できます。
SSH configの作成
テキストエディタにて、configファイルを作成します。
Host (任意の接続名)
Hostname (VMのipアドレス)
User (VM作成時に入力した管理者アカウント)
IdentityFile (公開鍵ファイルのパス)
私の場合だと、以下になりました。
Host azure.playground
Hostname ***.***.***.***
User player
IdentityFile C:\Users\quz\.ssh\azure_playground_id_rsa
VMに接続
「Git Bash」にてsshコマンドを叩いて接続しました。
結果のipアドレス部分は「***」にて潰しています。
途中、「Enter passphrase for key」部分で、公開鍵作成時のパスワード入力を求められます。
結果
$ ssh azure.playground
The authenticity of host '***.***.***.*** (***.***.***.***)' can't be established.
ECDSA key fingerprint is SHA256:au2uqcm39rd3QMfymkGDqd770Z70V6td2LjlbnXp3Xs.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '***.***.***.***' (ECDSA) to the list of known hosts.
Enter passphrase for key 'C:\Users\quz\.ssh\azure_playground_id_rsa':
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.18.0-1018-azure x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Sat May 18 05:23:28 UTC 2019
System load: 0.04 Processes: 115
Usage of /: 4.1% of 28.90GB Users logged in: 0
Memory usage: 75% IP address for eth0: 10.0.0.4
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.
player@playground:~$