客戶端ip:192.168.1.129mysql
服務器ip:192.168.1.130sql
第一步 客戶端生成密鑰對服務器
#ssh-keygen -t rsassh
Enter file in which to save the key (/root/.ssh/id_rsa): ide
表示密鑰保存位置默認:/root/.ssh/id_rsa 直接 enter鍵 默認spa
Enter passphrase (empty for no passphrase): 3d
Enter same passphrase again: rest
這表示輸入密碼 ,能夠直接enter鍵 ip
[root@lnmp ~]# cd /root/.ssh/lnmp
id_rsa是私鑰,id_rsa.pub是公鑰
[root@lnmp ~]#scp id_rsa.pub root@192.168.1.130:/tmp/
將公鑰上傳到服務器端
第二步 服務器端配置
[root@mysql ~]# cd /tmp/
查看一下是否上傳成功
[root@mysql tmp]# mkdir /root/.ssh
[root@mysql tmp]# chmod 700 /root/.ssh/
[root@mysql tmp]# cd /root/.ssh/
[root@mysql .ssh]# touch authorized_keys
[root@mysql .ssh]# cat /tmp/id_rsa.pub >> authorized_keys
把公鑰追加到密鑰文件中,而後驗證一下
關鍵的一步
[root@mysql ~]# chmod 600 /root/.ssh/authorized_keys
修改配置文件
RSAAuthentication yes rsa驗證
PubkeyAuthentication yes 密鑰驗證
AuthorizedKeysFile .ssh/authorized_keys 密鑰位置
修改前:
修改後
把密碼驗證也關掉
重啓一下ssh服務
[root@mysql ~]# /etc/init.d/sshd restart
驗證一下 ,沒有提示輸入密碼說明配置成功