密鑰對登錄

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

相關文章
相關標籤/搜索