ssh-keygen 用來(lái)生成ssh登錄的key,可以使我們以后登錄遠(yuǎn)程主機(jī)時(shí)無(wú)需再輸入遠(yuǎn)程主機(jī)的key.
具體使用方法如下:
例如我們有兩臺(tái)主機(jī):
A:192.168.0.1? B:192.168.0.2
當(dāng)我們需要用主機(jī)A登錄遠(yuǎn)程主機(jī)B時(shí)卵贱,我們?cè)谥鳈C(jī)A上輸入:
一喉童、# ssh-keygen -t rsa?
會(huì)產(chǎn)生如下的信息:
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):? ? ? ->輸入key文件的名稱
Enter passphrase (empty for no passphrase):? ? ? ? ? ? ? ? ?->輸入使用key時(shí)的密碼疾就,注意這里不是遠(yuǎn)處服務(wù)器的密碼,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 只是你使用sshkey時(shí)需要輸入的密碼,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 建議不輸入(如果要輸入這個(gè)密碼還不如直接輸入
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 遠(yuǎn)處主機(jī)的密碼:))
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:
11:ae:00:bd:92:bc:70:f8:4b:cb:47:06:7f:e2:73:21 root@xxxxxx
二志鹃、# scp id_rsa.pub 192.168.0.2:/root/.ssh/
三硫狞、ssh 192.168.0.2? ? ->登錄遠(yuǎn)程主機(jī)B
root@192.168.0.2's password: ->輸入密碼
四信轿、 # cd /root/.ssh? ? ->進(jìn)入到key目錄
? ? ? # cat id_rsa.pub >> authorized_keys
五、#chmod 700 .ssh
? ? ? #chmod 600? authorized_keys
六残吩、#exit? ? -> 推出遠(yuǎn)程B服務(wù)器
七财忽、#service sshd restart? ->重新啟動(dòng)ssh服務(wù)
八、#ssh 192.168.0.2? ->遠(yuǎn)程登錄到B測(cè)試下吧:)