CentOS系統中,在登錄SSH的時候需要密碼登錄,其實只要進行簡單的設置,就是實現SSH無密碼登錄,想要知道如何設置嗎?隨小編一起來學習下CentOS實現SSH無密碼登錄的方法吧。
一、環境配置
1、服務端:CentOS release 5.3 IP:222.73.115.198
2、客服端:CentOS release 5.8 IP:192.168.4.244
二、配置SSH無密碼登錄需要3步:
1、生成公鑰和私鑰
2、導入公鑰到認證文件,更改權限
3、測試
三、客戶端配置
1、在客戶端生成私鑰與公鑰;
# ssh-keygen
[root@jw02 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): #回車(代表無需密碼登陸)
Enter passphrase (empty for no passphrase): #回車
Enter same passphrase again: #回車
Your identification has been saved in /root/.ssh/id_rsa. #代表私鑰
Your public key has been saved in /root/.ssh/id_rsa.pub. #代表公鑰
The key fingerprint is:
04:45:0b:47:10:92:0c:b2:b9:d7:11:5b:49:05:e4:d9 root@jw02
[root@jw02 ~]# ls ~/.ssh/
id_rsa id_rsa.pub known_hosts
2、默認在 ~/.ssh或者/root/.ssh/目錄生成兩個文件:
公鑰為:id_rsa.pub
私鑰為:id_rsa
上一頁12下一頁共2頁
四、服務器的配置
1、將客戶端的公鑰id_rsa.pub復制到服務器/home/ken/.ssh/authorized_keys;
[root@mon .ssh]# cd
[root@mon ~]# cd /home/ken/.ssh/
[root@mon .ssh]# ll
total 12
-rw-r--r-- 1 ken ken 1192 Feb 5 13:17 authorized_keys
-rw-r--r-- 1 ken ken 5720 Feb 5 14:03 known_hosts
[root@mon .ssh]# vim authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAu3FLhX1VlMQvuxVq8RAfdYEZwYwvorJN/iYkZXOz/itUB6OhO+oIUCcyvaSEHVVOeaPlmcau8HtuBp1V2SmwVl8LpRNYRgeUkSnQKFbjm7z2ALkuL4wAuCC8dcoEflzAOysZfjxoF2h1jPl2pwPd2CWlmPcN5l1kjhpQGJHzgfkkrsC2VR4KJkeqGVckdaKTvBdwElKrwugQhBllWkhsHq+xfoHoQz3n+Jjclpf0vN4z5WRq5+x68akYEG2Sm1s+iYYxO0oOoCJNSEQY7wz1U5q84kwG+0tnPfZDNwIa3ImrEiq6eqdZ5L/rZzht+Hv95t3K39TUKNRbiXXaW+1LsQ== [email protected]
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAwO3o13oscFLnBlzFGPLNkJVNQd1LW2ff/EG0CFjZmw5e2ClqW1YV9fcrPMG4ifmXwmmuF8Ns9WcQAQU/S6RfKHytwHvgpNCeOamzkcfVchHLunk1IDsW3eWARBhKxxdK4pOatPJzcsGtdrBl/ba7W6Z6uYVMlgQzQK7hxI4gXyh6jxvn4gIJZTBvhfMCM1oki+eA38qZZ6zdCfjDc617kHeINQRkSIaUxikReL8X7RigiBPACohfNzKtImZca2oO5EHtDv1b4GuUMFwYSa//EMcwDug9pMQ2LMrOSxgWBokZxq3r/7bybZT+9eGvnwNYoZSej0/qq8A43rhnhXF4pQ== root@dev
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA17tmVraR6bpJXZVw7RH+uW3DjVRCv5itVP/9lgO2JePNwqPEy+SShZrlbjq/umziaEow5OrgYHWxlf2V1cqKhk2TR4y9ZD9B5lQTHudZO4I+JMV7wU/oEdBNl5S5RzYOIds6PnGUAEqmeCSLu3ozWZq0vDTokoLo41IdcgcLR1sqTOOViBP6oJKT5gG3ws96oe3c0s9irhuzAVE3zV3sptldRBDLKJSB+oXgpugE1WTEi6mGuNVgQc3VRZEWKNyAizVUJprGEZ2nBTeJGJb6NPRFcoNs9OdLpeSEXN/HsRLaMfJ6QMWC90azmmrDFm5BSxqntr+q6DVGGFILQWmPMw== root@jw02
[root@mon .ssh]#
2、如果沒有這個目錄的話,則# mkdir -p /root/.ssh
3、更改文件夾以及文件權限
[root@jw02 ~]#chmod 700 ~/.ssh
[root@jw02 ~]#chmod 600 ~/.ssh/authorized_keys
4、重新啟動SSH服務
[root@jw02 ~]# service sshd restart
五、測試
[root@jw02 script]# sftp -oPort=511190 [email protected]
Connecting to 222.73.115.198.。。
sftp》
如果沒有輸入密碼的提示就是成功了!
上面就是CentOS無密碼登錄SSH的方法介紹了,通過上面的設置,你不需要輸入密碼即可登錄SSH,為你節省了不必要的麻煩。
上一頁12 下一頁共2頁