2013-11-27 272 views
1

我想在兩個新鮮的linux虛擬機上從VM A到VM B設置無密碼ssh,但我遇到權限問題。我安裝了兩個虛擬機和配置的/ etc/SSH/sshd_config中的OpenSSH服務器如下:ssh無密碼登錄失敗,權限被拒絕(公鑰)

RSAAuthentication yes 
PubkeyAuthentication yes 
#AuthorizedKeysFile  %h/.ssh/authorized_keys 
PasswordAuthentication no 

的其他所有字段的默認值。在VM A上,我用默認選項運行ssh-keygen -t rsa。我試圖使用ssh-copy-id,但我得到了一個權限被拒絕(publickey)錯誤。然後,我手動將id_rsa.pub複製到VM B上的authorized_keys中。對於〜/ .ssh/id_rsa.pub,〜/ .ssh/authorized_keys,對於〜/ .ssh/id_rsa和chmod 644使用了chmod 700,對於〜/ .ssh,chmod 600,和兩個虛擬機上的〜/ .ssh/known_hosts。運行ssh -v VM-B後,我得到以下輸出:

OpenSSH_5.9p1 Debian-5ubuntu1.1, OpenSSL 1.0.1 14 Mar 2012 
debug1: Reading configuration data /etc/ssh/ssh_config 
debug1: /etc/ssh/ssh_config line 19: Applying options for * 
debug1: Connecting to hadoop-slave-1 [192.168.86.134] port 22. 
debug1: Connection established. 
debug1: identity file /home/hduser/.ssh/id_rsa type 1 
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048 
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048 
debug1: identity file /home/hduser/.ssh/id_rsa-cert type -1 
debug1: identity file /home/hduser/.ssh/id_dsa type -1 
debug1: identity file /home/hduser/.ssh/id_dsa-cert type -1 
debug1: identity file /home/hduser/.ssh/id_ecdsa type -1 
debug1: identity file /home/hduser/.ssh/id_ecdsa-cert type -1 
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1.1 
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1.1 pat OpenSSH* 
debug1: Enabling compatibility mode for protocol 2.0 
debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1.1 
debug1: SSH2_MSG_KEXINIT sent 
debug1: SSH2_MSG_KEXINIT received 
debug1: kex: server->client aes128-ctr hmac-md5 none 
debug1: kex: client->server aes128-ctr hmac-md5 none 
debug1: sending SSH2_MSG_KEX_ECDH_INIT 
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY 
debug1: Server host key: ECDSA 45:48:fd:f0:db:1a:2a:c0:80:17:ec:18:5a:dd:f2:a5 
debug1: Host 'hadoop-slave-1' is known and matches the ECDSA host key. 
debug1: Found key in /home/hduser/.ssh/known_hosts:1 
debug1: ssh_ecdsa_verify: signature correct 
debug1: SSH2_MSG_NEWKEYS sent 
debug1: expecting SSH2_MSG_NEWKEYS 
debug1: SSH2_MSG_NEWKEYS received 
debug1: Roaming not allowed by server 
debug1: SSH2_MSG_SERVICE_REQUEST sent 
debug1: SSH2_MSG_SERVICE_ACCEPT received 
debug1: Authentications that can continue: publickey 
debug1: Next authentication method: publickey 
debug1: Offering RSA public key: /home/hduser/.ssh/id_rsa 
debug1: Authentications that can continue: publickey 
debug1: Trying private key: /home/hduser/.ssh/id_dsa 
debug1: Trying private key: /home/hduser/.ssh/id_ecdsa 
debug1: No more authentication methods to try. 
Permission denied (publickey). 

是否還有其他我需要做的事?

+0

當調試sshd的准入問題,我經常發現它有助於在非守護模式,例如在遠程機器上運行的sshd 'sshd -D -d -p 8022'。然後在另一臺機器上輸入'ssh -p 8022 remotehost'。 sshd傾向於產生比ssh更多的信息錯誤輸出。 –

回答

2

嘗試按照Password-less logins with OpenSSH

尤其這應該工作:

ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected] 

這將提示您輸入該主機的登錄密碼,然後複製密鑰文件給你,創建正確的目錄並根據需要修復權限

+0

我曾嘗試過這一點,並有一個permissiondenied(publickey)錯誤,但這工作時,我暫時重新啓用密碼認證。在使用'ssh-copy-id'之前,我還不得不使用'ssh-add',這在之前我忽略了。 – user2623855

+0

僅供參考,我在https://github.com/centic9/generate-and-send-ssh-key創建了一個小腳本,它一次運行必要的步驟,另外還確保所有文件/目錄權限始終讓我頭疼... – centic

0

您發佈的日誌中的此行看起來不正確:

debug1: Offering RSA public key: /home/hduser/.ssh/id_rsa 

你能嘗試:

ssh-copy-id [email protected] 
+0

只要你知道:在IBM AIX上這不起作用,因爲沒有'ssh-copy-id'。 'chmod -R 755〜/ .ssh'雖然工作正常。 – RAKK