標籤:伺服器 private 安全性 public enter
應用情境:有時候我們要給遠在北京或者國外的開發人員伺服器的許可權,為了保證伺服器的安全性我們不想讓他們知道伺服器的root登陸密碼,所以我們可以給他們用秘鑰的登陸模式。
用戶端ip:192.168.0.163
伺服器ip:192.168.0.167
1.密鑰認證的產生
[[email protected] .ssh]# ifconfig eth0 | awk ‘/inet addr/{print }‘
inet addr:192.168.0.163 Bcast:192.168.0.255 Mask:255.255.255.0
[[email protected] .ssh]# 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:
8a:85:d9:37:a8:95:e2:06:0e:d3:18:91:11:60:11:68 [email protected]
The key‘s randomart image is:
+--[ RSA 2048]----+
|BBo |
|+E |
|o |
| + + o |
|+ o + * S |
| + o * o . |
| . = . |
| . |
| |
+-----------------+
公開金鑰已經產生
現在把公開金鑰上傳到另一台伺服器上去
[[email protected] .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]:/root/.ssh/
登入到伺服器上,查看公開金鑰是否上傳
[[email protected] ~]# ll /root/.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
配置完畢,現在開始登入一下
[[email protected] ~]# ssh 192.168.0.167
Address 192.168.72.129 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
Last login: Thu Aug 4 18:08:05 2011 from 192.168.0.163
[[email protected] ~]#
現在不用輸入密碼(,就可以登入了。退出登入
[[email protected] ~]# exit
logout
Connection to 192.168.0.167 closed.
linux ssh 密鑰認證無需輸入密碼即可登入,在設定密鑰的同時,也可以輸入密碼,即可密碼+密鑰認證就可以完成!
秘鑰無密碼的登入模式