SSH鍵認証設定
更新日 2022-12-16 10:18:03
centos
サーバー側設定
sshdの設定を変更する
$ su
パスワード:
# vi /etc/ssh/sshd_config
以下の行のコメントをはずして有効化する
#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys
sshd再起動
# service sshd restart
公開鍵・秘密鍵の生成(→クライアント用)
// ディレクトリ移動
$ cd ~/.ssh/
// 鍵を生成する
$ ssh-keygen -t rsa
とりあえずすべてEnter入力
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hoge/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/hoge/.ssh/id_rsa.
Your public key has been saved in /home/hoge/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:xbo5Lpx9e5OPI+Mrg//98hl7Lxq7TcQ8fUZHlL00Jqw hoge@hoge-Virtual-Machine
The key's randomart image is:
+---[RSA 2048]----+
| . .=|
| . o *.|
| o . + =|
| o E o +.|
| S = +|
| o . o.|
| . ++ ..o |
| =.+.+.**.+.|
| oo*=**XBoo|
+----[SHA256]-----+
クライアント用の公開鍵と秘密鍵が生成される
-rw------- 1 hoge hoge 1679 6月 9 06:52 id_rsa
-rw-r--r-- 1 hoge hoge 407 6月 9 06:52 id_rsa.pub
公開鍵をサーバー側のauthorized_keysファイルに設定する
$ cat id_rsa.pub >> authorized_keys
接続確認
クライアント側に秘密鍵を移動しておくクライアント側
tera term等のSSHクライアントソフトで接続時にダウンロードした秘密鍵を選択するおわり