ここでは、WebVirtMgrのWeb画面から管理したいハイパーバイザーにSSH接続するために必要なセットアップをする。
SSH接続するための利用する認証用の鍵を作成する(WebVirtMgrをインストールしたホストサーバー上で実施する)。
■ nologin(ログインが許可されていない)の nginx ユーザーに切替え
$ sudo su - nginx -s /bin/bash
[sudo] のパスワード:
-bash-4.2$
■ SSHで利用する認証用の鍵を生成
-bash-4.2$ ssh-keygen -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/nginx/.ssh/id_rsa):
Created directory '/var/lib/nginx/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/lib/nginx/.ssh/id_rsa.
Your public key has been saved in /var/lib/nginx/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:bbY2fE3gP7lb6CYzh3Z1SBY3H1q70BsLIOywTMxKxd4 nginx@localhost.localdomain
The key's randomart image is:
+---[RSA 4096]----+
| =.. |
| . * o . .+.|
| . = = . o +o=|
| . + E . =o+.|
| S + .o+.=|
| + . +.*o|
| = ..*.o|
| . o*.++ |
| . B+. |
+----[SHA256]-----+
-bash-4.2$
SSHクライアントの設定ファイルを作成する。ここで作成するファイルは、リモートサーバーに接続する際に必要な設定ファイルで、SSH接続時の情報を定義しておくことで、ssh コマンドで毎回サーバーへ接続する手間を省略できる。
■ SSHクライアントの設定ファイル作成
-bash-4.2$ touch ~/.ssh/config && echo -e "StrictHostKeyChecking=no\nUserKnownHostsFile=/dev/null" >> ~/.ssh/config
-bash-4.2$
捕捉)
StrictHostKeyChecking=no は、SSH初回接続時に行われる対話的なやりとり(yes/no)?を省略するために設定。
nUserKnownHostsFile=/dev/null は、ホスト情報をknown_hostsに残らないようにし、ホスト鍵が変わっても手動でエントリを消す必要を無くすために設定。
作成した /.ssh/config のパーミッション(アクセス権限)を設定する。
-bash-4.2$ chmod 0600 ~/.ssh/config
-bash-4.2$
-bash-4.2$ exit
webvirtmgr ユーザを追加し、適切なグループに追加する(管理したいハイパーバイザー のホストサーバ上で実施する)。
■ ユーザーの追加
$ sudo adduser webvirtmgr
$
■ ユーザーのパスワード登録
$ sudo passwd webvirtmgr
ユーザー webvirtmgr のパスワードを変更。
新しいパスワード:
よくないパスワード: このパスワードには一部に何らかの形でユーザー名が含まれています。
新しいパスワードを再入力してください:
passwd: すべての認証トークンが正しく更新できました。
$
■ 作成したユーザーをグループに追加
$ sudo usermod -G libvirt -a webvirtmgr
$
webvirtmgrをインストールしたホストサーバーに戻り、作成した公開鍵を管理したいハイパーバイザーのホストサーバーへコピーする。ここでは、webvirtmgrと管理したいハイパーバイザーが、同一ホストサーバーにある環境を前提にしているため、webvirtmgrでSSH接続するホストサーバーはlocalhostとしています。
■ nologin(ログインが許可されていない)の nginx ユーザーに切替え
$ sudo su - nginx -s /bin/bash
[sudo] yuji のパスワード:
最終ログイン: 2018/09/29 (土) 22:50:49 JST日時 pts/2
-bash-4.2$
■ 作成した公開鍵をコピー
-bash-4.2$ ssh-copy-id webvirtmgr@localhost
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/var/lib/nginx/.ssh/id_rsa.pub"
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
webvirtmgr@localhost's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'webvirtmgr@localhost'"
and check to make sure that only the key(s) you wanted were added.
-bash-4.2$
ハイパーバイザーのホストサーバーへのSSH接続が、パスワード要求されずにできることを確認する。
■ SSH認証用の公開鍵を持っているアカウント(webvirtmgr)
※ パスワードの入力を求められない
-bash-4.2$ ssh webvirtmgr@localhost
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
Last login: Sat Sep 29 23:11:36 2018 from localhost
[webvirtmgr@localhost ~]$
■ SSH認証用の公開鍵を持っていないアカウント(test)
※ パスワードの入力が求められる
-bash-4.2$ ssh test@localhost
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
test@localhost's password:
Last login: Sun Oct 7 13:23:42 2018
[test@localhost ~]$