RHEL9 passwordなしでsshログインする方法

環境
# cat /etc/redhat-release
Red Hat Enterprise Linux release 9.2 (Plow)

操作方法
1.ssh-keyを作成します
# ssh-keygen -t rsa

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): #Enterキーを押下
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:cglxAn+Ym9OWJWn+Pt1ArsPz3IRZFuK5uUPVkR41j5w root@localhost.localdomain
The key's randomart image is:
+---[RSA 3072]----+
| ..o . .+|
| . * . . *o|
| = = . . E.+|
| O = ..o.o.|
| = S oo.o |
| = . +B |
| ..+=o. |
| .*.o+. |
| .=+.. |
+----[SHA256]-----+
Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): #Enterキーを押下 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:cglxAn+Ym9OWJWn+Pt1ArsPz3IRZFuK5uUPVkR41j5w root@localhost.localdomain The key's randomart image is: +---[RSA 3072]----+ | ..o . .+| | . * . . *o| | = = . . E.+| | O = ..o.o.| | = S oo.o | | = . +B | | ..+=o. | | .*.o+. | | .=+.. | +----[SHA256]-----+
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): #Enterキーを押下
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:cglxAn+Ym9OWJWn+Pt1ArsPz3IRZFuK5uUPVkR41j5w root@localhost.localdomain
The key's randomart image is:
+---[RSA 3072]----+
|    ..o .      .+|
|     . * .   . *o|
|      = = . . E.+|
|       O = ..o.o.|
|      = S  oo.o  |
|       = .  +B   |
|         ..+=o.  |
|         .*.o+.  |
|          .=+..  |
+----[SHA256]-----+

2.ディレクトリ(~/.ssh/)を確認して鍵を確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# ls ~/.ssh
id_rsa id_rsa.pub
# ls ~/.ssh id_rsa id_rsa.pub
# ls ~/.ssh
id_rsa id_rsa.pub

3.sshしたいサーバー側に公開鍵(public key)をコピーします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ ssh-copy-id -i ~/.ssh/id_rsa.pub <ユーザー名>@<ipアドレス>:
$ ssh-copy-id -i ~/.ssh/id_rsa.pub <ユーザー名>@<ipアドレス>:
$ ssh-copy-id -i ~/.ssh/id_rsa.pub <ユーザー名>@<ipアドレス>:

ユーザーのパスワードが要求されるので入力すると、
サーバー側にログインして、~/.ssh/authorized_keysというファイルの中にpublic keyが保存されていることが確認できます。

4.動作確認

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# ssh arte@192.168.44.133
Activate the web console with: systemctl enable --now cockpit.socket
Register this system with Red Hat Insights: insights-client --register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last login: Sun Feb 25 18:55:12 2024 from 192.168.44.1
# ssh arte@192.168.44.133 Activate the web console with: systemctl enable --now cockpit.socket Register this system with Red Hat Insights: insights-client --register Create an account or view all your systems at https://red.ht/insights-dashboard Last login: Sun Feb 25 18:55:12 2024 from 192.168.44.1
# ssh arte@192.168.44.133
Activate the web console with: systemctl enable --now cockpit.socket

Register this system with Red Hat Insights: insights-client --register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last login: Sun Feb 25 18:55:12 2024 from 192.168.44.1

 

RHEL9

Posted by arkgame