バックグラウンド:
ホストA(node32)には、ホストB(node33)へのパスワードなしのログインが必要です。
ステップ:
1.ホストAで次のコマンドを実行し、Enterキーを押し続けて、公開鍵と秘密鍵を含む鍵ペアを生成します。
ssh-keygen -t rsa
Enterキーを押し続けると、表示は次のようになります。
[root@node32 .ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:ACaurLVh+vMvDPOB4tGK4XZjegO7IsTfK0Rj0c35kPA [email protected]
The key's randomart image is:
+---[RSA 2048]----+
| . +.+ o |
| . + o.* |
| . . .Eo |
|.. + . . |
|o.B.. S |
|+O+=. |
|BoO=.. |
|+B.O+. |
|+oBo=+o |
+----[SHA256]-----+
〜/ .ssh /ディレクトリの下に2つのファイルが生成されます:秘密鍵:id_rsa公開鍵:id_rsa.pub
2.ホストAで次のコマンドを実行して、生成された公開鍵をホストBに送信します
ssh-copy-id node33
ホストBのrootパスワードを入力して操作を完了します。表示は次のとおりです。
[root@node33 .ssh]# ssh-copy-id node33
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'node33 (172.16.18.33)' can't be established.
ECDSA key fingerprint is SHA256:591R1j/G7VowLEhaiZoIXQZ2hfJyk8T7kf8h5BjEshE.
ECDSA key fingerprint is MD5:ac:a8:0a:5d:d4:1d:f5:29:28:8d:12:98:c8:22:b3:1e.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@node32's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'node33'"
and check to make sure that only the key(s) you wanted were added.
実施する:
これで、ホストAで秘密なしにホストBへの接続を試みることができます。
ssh node33
注:パスワードの入力も必要になる場合があります。これは、アクセス許可のためです。/rootディレクトリのアクセス許可:700 .ssh /ディレクトリのアクセス許可:700authorized_keysファイルのアクセス許可:700または600