公開鍵認証を利用します。
[test@server1 ~]$ ssh-keygen ← 鍵ペアを作成します。
Generating public/private rsa key pair.
Enter file in which to save the key (/home/test/.ssh/id_rsa): ← 変更の必要がなければEnterキーを押します。
Created directory ‘/home/test/.ssh’.
Enter passphrase (empty for no passphrase): ← パスフレーズを設定します。 (パスフレーズが必要ない場合はEnterキーを押します。)
Enter same passphrase again:
Your identification has been saved in /home/test/.ssh/id_rsa
Your public key has been saved in /home/test/.ssh/id_rsa.pub
The key fingerprint is:
[test@server1 ~]$ ll ~/.ssh
合計 8
-rw——- 1 test test 2655 8月 3 22:49 id_rsa
-rw-r–r– 1 test test 566 8月 3 22:49 id_rsa.pub
[test@server1 ~]$ mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
↓ /etc/ssh/sshd_config を編集します。
PubkeyAuthentication yes ← 公開鍵認証を許可します。
PasswordAuthentication no ← パスワード認証不可に変更します。
[test@server1 ~]$ sudo systemctl restart sshd ← sshdを再起動します。