====== 06 sshでパスワードなしにログインするには ====== ^ログイン元|| |ホスト名|ssh-host01| |IP|192.168.10.20| |ユーザ|hoge2| ^リモート側|| |ホスト名|ssh-host02| |IP|192.168.10.50| |ユーザ|hoge5| ===== ①ログイン元で鍵作成 ===== 下記で、$HOME/.ssh/ディレクトリに秘密鍵(id_rsa)と公開鍵(id_rsa.pub)が作成される。 ※ログイン元(ユーザ:hoge2)のユーザで作成 hoge2@ssh-host01 $ ssh-keygen -t rsa ←RSA暗号方式の鍵を作成 Generating public/private rsa key pair. Enter file in which to save the key (/home/nori/.ssh/id_rsa): ←[Enter]キー Enter passphrase (empty for no passphrase): ←パスフレーズを入力 Enter same passphrase again: ←同じパスフレーズを入力 Your identification has been saved in /home/nori/.ssh/id_rsa. Your public key has been saved in /home/nori/.ssh/id_rsa.pub. The key fingerprint is: f9:81:b6:c7:8f:b9:aa:3e:0e:c6:bd:35:19:a1:1e:06 nori@pandora ===== ②リモート側で公開鍵をコピー ===== 次に、リモート側で、先ほど作成した公開鍵を ~/.ssh/authorized_keysに追加し、パーミッションを600に変更する。 ※ログイン元(ユーザ:hoge5)のユーザで作成 hoge5@ssh-host02 $ cat id_rsa.pub >> $HOME/.ssh/authorized_keys hoge5@ssh-host01 $ chmod 600 $HOME/.ssh/authorized_keys ===== ③ログイン確認 ===== ログイン元(ユーザ:hoge2)から、リモート側(ユーザ:hoge5)へsshし鍵でログインできる事を確認 hoge2@ssh-host01 $ ssh hoge5@[リモート側IP] {{tag>ssh}}