接続元で、公開鍵と鍵ペアと作ります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
$ ssh-keygen -t rsa 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:6QIg7y3cG5JtHPILGkSKE480kwmY5EbljMiUXwQ2yAKB48 hoge@hogehoge The key's randomart image is: +---[RSA 2048]----+ |*%=+o | |BE*oo | |*+* B.B | |o= +. . . | | oo.oo S | |oo.Ooo . | |o B.O . . | | o = + . | |. o | +----[SHA256]-----+ $ $ ls .ssh/id* .ssh/id_rsa .ssh/id_rsa.pub |
作った鍵の公開鍵(id_rsa.pub)だけを、接続先のサーバの “~/.ssh/authorized_keys” に追加します。(ない場合は作られます。)
1 2 3 4 5 6 7 |
# 接続元 $ scp .ssh/id_rsa.pub example.com:~/ hoge@example.com's password: id_rsa.pub 100% 402 353.3KB/s 00:00 # 接続先 $ cat id_rsa.pub >> .ssh/authorized_keys |
これで完了。
公開鍵認証でssh接続できるか確認してみてください。