在linux下使用遠端複製命令scp時會出現去掉密碼提示的方法

okone96發表於2007-09-04

網上找了半天,都不夠簡單明瞭,我自己總結以下:

把你的本地主機使用者的ssh公匙檔案寫入到遠端主機使用者的~/.ssh/authorized_keys檔案中,具體方法
假設本地主機localhost,遠端主機remote

一,在localhost主機裡的使用者

執行 ssh-keygen -t rsa
結果如下
Generating public/private rsa key pair.

Enter file in which to save the key (/home/.username/ssh/id_rsa):#回車

Enter passphrase (empty for no passphrase):#回車

Enter same passphrase again:#回車

Your identification has been saved in /home/.username /.ssh/id_rsa.

Your public key has been saved in /home/.username /.ssh/id_rsa.pub.

The key fingerprint is:

38:25:c1:4d:5d:d3:89:bb:46:67:bf:52:af:c3:17:0c

Generating RSA keys:

Key generation complete.
會在使用者目錄~/.ssh/產生兩個檔案,id_rsa,id_rsa.pub

二,把id_rsa.pub檔案複製到remote主機的使用者目錄下

cat id_rsa.pub >~/.ssh/authorized_keys
就可以了

這樣localhost主機的使用者就可以透過ssh而不用密碼登陸remote主機

在測試當中發現經常出現以下錯誤:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
1f:a3:2b:b5:27:0c:5c:7b:89:27:ff:ab:cd:ba:31:66.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending key in /root/.ssh/known_hosts:6
RSA host key for 60.28.15.234 has changed and you have requested strict checking.
Host key verification failed.

解決辦法是把known_hosts檔案刪掉就可以了

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/750220/viewspace-967849/,如需轉載,請註明出處,否則將追究法律責任。

相關文章