SSH簡介:
傳統的網絡服務程式,SSH的英文全稱是 Secure Shell,通過使用ssh,可以對所有的傳輸的資料進行加密,這樣既可以防止攻擊又可以防止IP欺騙。
SSH 提供2種級别的安全驗證
1,基于密碼的安全驗證,這也是我們常用的一種,隻要知道使用者名和密碼,就可以遠端登陸到遠端主機上。
2,基于密鑰的安全認證,就是說使用者必須為自己建立一對密鑰,并把公用密鑰放到需要通路的伺服器上。
2種安全級别的驗證,後者相對比前者更安全一些,第二種級别不需要在網絡上傳遞密碼。
SSH密鑰認證登入配置
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIiZpdmLz5WYyR3LcdWbp9CXzNXZyBHZy92dvw1cul2Z1xGcvwVZj1WeulGdvw1cq9CXzVGZ1x2YulWLwd3Lc12bj5Sa25Wd55yZvxmYvw1LcpDc0RHaiojIsJye.gif)
原理:使用者首先需要為自己建立一對密鑰:公鑰(用在登入的伺服器上)和私鑰。OPENSSH 公開的密鑰的密碼體質有RSA,DSA等,這裡就用RSA。
用戶端ip:192.168.72.11
伺服器ip:192.168.72.129
1.密鑰認證的生成
[root@xyly ~]# ifconfig eth0 | awk '/inet addr/{print }'
inet addr:192.168.72.11 Bcast:192.168.72.255 Mask:255.255.255.0
[root@xyly ~]# ssh-keygen -t rsa
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:c5:7a:57:f6:2e:9c:1f:b5:e7:45:b3:11:f3:c7:18 root@xyly
公鑰已經生成
現在把公鑰上傳到另一台伺服器上去。
[root@xyly ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected]
15
The authenticity of host '192.168.72.129 (192.168.72.129)' can't be established.
RSA key fingerprint is 3b:26:19:2e:51:ca:cc:de:ac:bc:00:09:f0:7c:7d:f1.
Are you sure you want to continue connecting (yes/no)? yes #由于是第一次登入,伺服器要進行确認
Warning: Permanently added '192.168.72.129' (RSA) to the list of known hosts.
Address 192.168.72.129 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
[email protected]'s password:
Now try logging into the machine, with "ssh '[email protected]'", and check in:
.ssh/authorized_keys #把公鑰上傳的位置和公鑰的檔案名
to make sure we haven't added extra keys that you weren't expecting.
登入到伺服器上,檢視公鑰是否上傳
[root@localhost ~]# ll .ssh/authorized_keys
-rw------- 1 root root 391 Aug 4 18:31 .ssh/authorized_keys
說明公鑰上傳成功了。
修改ssh配置檔案,設定公鑰認證登入
将下邊2行的注釋去掉,重新開機ssh服務
RSAAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
/etc/init.d/sshd restart
配置完畢,現在開始登入一下
[root@xyly ~]# ssh 192.168.72.129
Last login: Thu Aug 4 18:08:05 2011 from 192.168.72.1
[root@localhost ~]#
現在不用輸入密碼,就可以登入了。登出