はじめに
VirtualBoxでパスワード認証を検証しました。勉強のため、記事にまとめました。
認証は3種類あります。
パスワード認証とは、鍵を使わずにパスワードを入力することでSSH接続すること
ホスト認証とは、接続先のホストが正しいホストかどうかを確認するために行う。
公開鍵認証とは、秘密鍵と公開鍵でSSH接続すること
前提条件
VirtualBoxをインストール済みであること
OSはCentOS7であること
インターネットに接続できる環境であること
接続先のサーバー用とクライアントのサーバー用 計2台のゲストOSを作成する事
ネットワークはブリッジを使用していること
検証環境
クライアントサーバー(192.168.0.3) test-clientユーザーから接続先のサーバ(192.168.0.2) testユーザーへSSH接続を試してみた
パスワード認証
接続先のサーバ(192.168.0.2) パスワード認証設定
接続先のサーバの/etc/ssh/sshd_configのPasswordAuthentication yesして
パスワード認証を許可した
[root@localhost ssh]# ip a | grep 192.168.0.2
inet 192.168.0.2/24 brd 192.168.0.255 scope global noprefixroute enp0s3
[root@localhost ssh]#
[root@localhost ssh]#
[root@localhost ssh]# cat /etc/ssh/sshd_config | grep "Pass"
PasswordAuthentication yes
#PermitEmptyPasswords no
#PasswordAuthentication no
#KerberosOrLocalPasswd yes
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication, then enable this but set PasswordAuthentication
[root@localhost ssh]#
sshdを再起動して、上記の設定ファイルを反映させた
[root@localhost ssh]# systemctl restart sshd
クライアントサーバー(192.168.0.3)から接続先のサーバ(192.168.0.2) へSSH接続した
※SSH接続前のサーバーのIPアドレス確認した
[test-client@localhost .ssh]$ ip a | grep 192.168.0.3
inet 192.168.0.3/24 brd 192.168.0.255 scope global noprefixroute enp0s3
[test-client@localhost .ssh]$ ssh test@192.168.0.2
※はじめて接続先のサーバ(192.168.0.2)へ接続したため、メッセージが表示されています。
The authenticity of host '192.168.0.2 (192.168.0.2)' can't be established.
ECDSA key fingerprint is SHA256:zJtPkxcl+vb5k7IYvTmZMJW2y5HBrzhhEJ+tORk62bA.
ECDSA key fingerprint is MD5:8c:59:23:33:1d:8e:56:dc:4c:87:e3:33:aa:3d:2f:c1.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.2' (ECDSA) to the list of known hosts.
test@192.168.0.2's password:
Last login: Mon Jun 6 07:07:49 2022
[test@localhost ~]$
※ipアドレスから接続先のサーバ(192.168.0.2)へSSH接続できたことが分かった
[test@localhost ~]$ ip a | grep 192.168.0.2
inet 192.168.0.2/24 brd 192.168.0.255 scope global noprefixroute enp0s3
[test@localhost ~]$
接続先サーバーのフィンガープリントを確認してみた
初めてSSH接続したサーバーの場合、フィンガープリントが表示されます。
接続するサーバーが本物か確認するために、接続先サーバーのフィンガープリントを事前に確認する必要があります。
以下のサイトに詳しく説明しています。とても勉強になりました。
https://rurukblog.com/post/ssh-fingerprint/
[root@localhost ssh]#
[root@localhost ssh]# ssh-keygen -lf ssh_host_ecdsa_key.pub
256 SHA256:zJtPkxcl+vb5k7IYvTmZMJW2y5HBrzhhEJ+tORk62bA no comment (ECDSA)
known_hostsファイルを確認してみた
2回目から同じサーバーへSSH接続する際は、known_hostsに接続先のサーバーのホスト公開鍵が設定されるため、メッセージが表示されなくなる。
上記は、ホスト認証と呼ばれています。
補足
ホストOSからゲストOSへTeraTermでSSH接続する際に、ユーザー名とパスワードで接続できるのは、パスワード認証が許可されているからです。
[root@localhost ssh]#
[root@localhost ssh]# ip a | grep 192.168.0.2
inet 192.168.0.2/24 brd 192.168.0.255 scope global noprefixroute enp0s3
[root@localhost ssh]#
[root@localhost ssh]# cat sshd_config | grep "Pass"
PasswordAuthentication no
#PermitEmptyPasswords no
#PasswordAuthentication no
#KerberosOrLocalPasswd yes
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication, then enable this but set PasswordAuthentication
[root@localhost ssh]#
[root@localhost ssh]# systemctl restart sshd
[root@localhost ssh]#
再度、ホストOSからゲストOSへTeraTermでSSH接続してみた
パスワード認証が許可されていないため、SSH接続に失敗しました。