2013-11-27 108 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