我在Google计算引擎上运行的Ubuntu 14.04 LTS有两个实例(主机名是namenode和datanode1)。 我正在努力设置它们之间的ssh root访问权限。
我提供了一些信息,以便您可以帮我解决这个问题
我在namenode上生成了密钥对(namenode,namenode.pub)。 namenode上的公钥如下所示
root@namenode:~# cat .ssh/namenode.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCsxYETzfP3Kv9QgRZ5AnJGu6LNTuAJj67DhUzJVad1Cis7qQ7X7GSv1S+HQESiK/H1u3duVunMB+eiV1ktF/V42r5o3HCTTckiChSuu4B+wkHCqaHFYtGJZIMncPb4CvuyhzPz+Zb
mlV7YRGqw5lO+cQLSxCQpmBkIR1iQHRbtLIRenUTI3cXnJ22OhRea63R1/d+LspJreI8lnfmVLMr3MLUfi/U2vX3kR2EaH1QAoO1+dnRzuqsZE/ehbzT/DfBifRdoRCzhXuWgNKNxc/O0V3MwflnvPaWxxDC7FNQ7//nFg4gl8j4yV8
XFvuCyzJTQ9nS3wN+6Dms7MfDQtl4v root@namenode
我将此公钥添加到datanode1的授权密钥。
root@datanode1:~# cat .ssh/authorized_keys
# namenode
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCsxYETzfP3Kv9QgRZ5AnJGu6LNTuAJj67DhUzJVad1Cis7qQ7X7GSv1S+HQESiK/H1u3duVunMB
+eiV1ktF/V42r5o3HCTTckiChSuu4B+wkHCqaHFYtGJZIMncPb4CvuyhzPz+ZbmlV7YRGqw5lO+cQLSxCQpmBkIR1iQHRbtLIRenUTI3cXnJ22OhR
ea63R1/d+LspJreI8lnfmVLMr3MLUfi/U2vX3kR2EaH1QAoO1+dnRzuqsZE/ehbzT/DfBifRdoRCzhXuWgNKNxc/O0V3MwflnvPaWxxDC7FNQ7//n
Fg4gl8j4yV8XFvuCyzJTQ9nS3wN+6Dms7MfDQtl4v root@namenode
我添加了这样的身份
root@namenode:~# eval `ssh-agent -s`
Agent pid 4030
root@namenode:~# ssh-add .ssh/namenode
Identity added: .ssh/namenode (.ssh/namenode)
这是详细输出
root@namenode:~# ssh -v -i .ssh/namenode.pub root@datanode1
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to datanode1 [10.240.218.126] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file .ssh/namenode.pub type 1
debug1: identity file .ssh/namenode.pub-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA b8:70:6e:f6:8c:4e:8e:ed:2b:46:d6:d4:d9:4d:ec:bb
debug1: Host 'datanode1' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:4
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: .ssh/namenode.pub
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
请帮我解决这个问题。我从那以后一直在苦苦挣扎。
答案 0 :(得分:1)
ssh -v -i .ssh/namenode.pub root@datanode1
在命令行中指定ssh密钥时,它应该是私钥文件,而不是公共文件。因此,您应在此处引用.ssh/namenode
,而不是.ssh/namenode.pub
。
看起来您已将私钥添加到ssh-add
,但ssh调试跟踪中没有任何迹象表明它与ssh代理通信或将私钥提供给远程服务器。也许您在ssh-add命令的不同会话(终端窗口)中运行了ssh,因此ssh无法访问环境变量,告诉它如何访问代理。
最后,namenode.pub
行的内容是一条长行。确保将其作为一条长行而不是三行复制到远程authorized_keys
文件中。