密钥对登录

客户端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

WEBRESOURCE86ee058ffbf7ecef12acf62902126

[root@lnmp ~]# cd /root/.ssh/lnmp

WEBRESOURCEd4e26e294740e62c5618b3d76fc56

id_rsa是私钥,id_rsa.pub是公钥

[root@lnmp ~]#scp id_rsa.pub root@192.168.1.130:/tmp/

将公钥上传到服务器端

WEBRESOURCEb324d6b3e9b58679958140fb51695

第二步 服务器端配置

[root@mysql ~]# cd /tmp/

查看一下是否上传成功

WEBRESOURCE4e335b9de9aacd402decd6b0b754e

[root@mysql tmp]# mkdir /root/.ssh

[root@mysql tmp]# chmod 700 /root/.ssh/

WEBRESOURCEcb75eb6017d1226dfea9187dcac40

[root@mysql tmp]# cd /root/.ssh/

[root@mysql .ssh]# touch authorized_keys

WEBRESOURCEec3ed702fee199473c430cb779521

[root@mysql .ssh]# cat /tmp/id_rsa.pub >> authorized_keys

把公钥追加到密钥文件中,而后验证一下

WEBRESOURCE080d00bb56e01a791fa84e6ed803d

关键的一步  

[root@mysql ~]# chmod 600 /root/.ssh/authorized_keys

WEBRESOURCE4d403fbdda0d174eaeae4d617bda1

修改配置文件

RSAAuthentication yes                      rsa验证

PubkeyAuthentication yes                 密钥验证

AuthorizedKeysFile      .ssh/authorized_keys            密钥位置

修改前:

WEBRESOURCEb3efa3d009031cf3e16207f4f212a

修改后

WEBRESOURCE77b71037c3f2215912208e65daacd

把密码验证也关掉

WEBRESOURCE3039154ccf429022b78ce2282f255

重启一下ssh服务

[root@mysql ~]# /etc/init.d/sshd restart

验证一下 ,没有提示输入密码说明配置成功

WEBRESOURCEbb783371ff38e6b95d7403bdc3b7c