SSH自動ログイン設定
SSHクライアントキーにて相手サーバーに自動ログイン設定する手順です。 CentOS 6.x対応 CentOS 7.x対応
サーバー側の認証でキー認証が有効である前提です。
パスフレーズを設定していない手順と成ります。
1 「scp ~/.ssh/id_rsa.pub 相手先ユーザー名@相手先ホスト:~/.ssh/適当な名称」を入力
[root@centos ~]# scp ~/.ssh/id_rsa.pub root@centos2:~/.ssh/centos.pub The authenticity of host 'centos2 (centos20)' can't be established. RSA key fingerprint is 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'centos2' (RSA) to the list of known hosts. root@centos2's password: id_rsa.pub 100% 406 0.4KB/s 00:00
3 対象サーバーへログイン後「cat /.ssh/適当な名称 >> ~/.ssh/authorized_keys」を入力
[root@centos2 ~]# cat /.ssh/centos.pub >> ~/.ssh/authorized_keys
* 接続元より再度自動ログイン確認
[root@centos ~]# ssh root@centos2 ls .ssh #確認 authorized_keys id_rsa id_rsa.pub