ssh-keygen

 大家都會,就當是誰忘了的時候,做個提醒的吧。。。

 ssh 是一個專爲遠程登錄會話和其他網絡服務提供安全性的協議。默認狀態下ssh鏈接是需要密碼認證的,可以通過添加系統認證(即公鑰-私鑰)的修改,修改後系統間切換可以避免密碼輸入和ssh認證。以下將創建過程簡單介紹下。
 
一、用ssh-keygen創建公鑰
haifeng@haifeng-EX38-DS4:/$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/haifeng/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/haifeng/.ssh/id_rsa.
Your public key has been saved in /home/haifeng/.ssh/id_rsa.pub.
The key fingerprint is:
7b:75:98:eb:fd:13:ce:0f:c4:cf:2c:65:cc:73:70:53 haifeng@haifeng-EX38-DS4
The key's randomart p_w_picpath is:
+--[ RSA 2048]----+
|                E|
|                .|
|              ...|
|             + =.|
|        S   + +.*|
|         . . + Bo|
|        . . . = =|
|         . . . * |
|            . ..=|
+-----------------+
 
##輸入後,會提示創建.ssh/id_rsa、id_rsa.pub的文件,其中第一個爲密鑰,第二個爲公鑰。過程中會要求輸入密碼,爲了ssh訪問過程無須密碼,可以直接回車 。
2.查看鑰匙。
[root@localhost .ssh]# ls ~/.ssh/
id_rsa  id_rsa.pub  known_hosts

###可以發現 ssh目錄下的兩枚鑰匙。
3.將公鑰複製到被管理機器上面
[root@localhost .ssh]# scp id_rsa.pub [email protected]:~/.ssh/authorized_keys
[email protected]'s password: 
id_rsa.pub                                    100%  408     0.4KB/s   00:00
4.訪問
# ssh 192.168.36.194
The authenticity of host '<Game2> (<192.168.36.194>)' can't be established. 
RSA key fingerprint is 34:b9:92:06:53:e6:91:4d:47:92:73:57:78:6a:5d:09. 
Are you sure you want to continue connecting (yes/no)?yes 
Warning: Permanently added '<Game2> (<192.168.36.194>' (RSA) to the list of known hosts. 

這是因爲首次訪問後,ssh會在.ssh/known_hosts中保存各個認證過的主機信息:
192.168.36.194 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAppStzIRxeFn0e737z7KO1tdm6CJUoLapaaoBDZqHy0Z11cUAmpg02dbrqwU7TBY9lDFwWQcry+W8X8qk1CoPdzu8YcMCpw5425mai0/RxkB/RPZ1putL2DQrRBMRTU1m5meLOYRXYlnU5E+YElCgH+ZJ8EXiurOzDvw6vi7pASi9wMQuJosFyNmv5E9/8ULgaKg3LtvP+0O1wPxrHOBDwVq2u9Oi7T2pX8deBEnOI4uG4CGXn/p0ml+uuS4DO3Up2VjqoRtqtuzWExnTyAGS/wQNnN3mera1ERya3FomEVHJRV5K2zJRkgSF8WfETXzQ2rAliOsW/YLTGF8vVvjo5w==
5.再次訪問,ssh登錄發現可以不用密碼登錄。
[root@localhost .ssh]# ssh 192.168.36.194
Last login: Fri Apr 22 00:56:45 2011 from 192.168.18.44
[root@Game2 ~]# 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章