標籤:伺服器 private 安全性 public enter
應用情境:有時候我們要給遠在北京或者國外的開發人員伺服器的許可權,為了保證伺服器的安全性我們不想讓他們知道伺服器的root登陸密碼,所以我們可以給他們用秘鑰加密碼的登陸模式。
原理:公開金鑰加密 私密金鑰解密。公開金鑰和私密金鑰是成對產生的,所以將私密金鑰發給別人別人也能登陸
用戶端ip:192.168.0.186
伺服器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] .ssh]# scp id_rsa.pub [email protected]:/root/.ssh/
登陸到伺服器上:
伺服器把用戶端公開金鑰重新命名
[[email protected] .ssh]# mv id_rsa.pub authorized_keys
修改ssh設定檔,設定公開金鑰認證登入
將下邊2行的注釋去掉,重啟ssh服務
RSAAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
/etc/init.d/sshd restart
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/49/3E/wKioL1QRVjXwj4VUAAENYwzCf9k114.jpg" title="1.png" alt="wKioL1QRVjXwj4VUAAENYwzCf9k114.jpg" />
配置完畢,現在開始登入一下
[[email protected] .ssh]# ssh 192.168.0.167
Enter passphrase for key ‘/root/.ssh/id_rsa‘:
Last login: Wed Sep 10 05:20:47 2014 from 192.168.0.186
[[email protected] ~]#
現在輸入之前設定秘鑰的密碼,就可以登入了。退出登入
[[email protected] ~]# exit
logout
Connection to 192.168.0.167 closed.
linux ssh 密鑰認證和秘鑰密碼即可登入。
當開發人員用完伺服器之後我們在伺服器上刪除公開金鑰即可。開發人員就無法登陸了。
如果其他客戶機也要登陸這台伺服器我們只需要將用戶端的私密金鑰發給其他人就可以登陸了。
是不是很牛逼啊。。。。。
秘鑰加密碼的登入模式