我有两个在 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 [email protected] none
debug1: kex: client->server aes128-ctr [email protected] 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).
datanode1 上授权密钥的权限是
-rw------- 1 root root 3695 Mar 19 18:53 .ssh/authorized_keys
请帮我解决这个问题。我已经挣扎了两天了。
答案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
作为一行长行复制到远程文件中,而不是三行。