Ubuntu 中的 Hadoop:无法创建无密码 SSH

Ubuntu 中的 Hadoop:无法创建无密码 SSH

我正在学习 Hadoop,并尝试按照书中定义的步骤创建无密码 SSH:Hadoop:权威指南

配置 SSH

伪分布式模式只是完全分布式模式的一个特例,其中(单个)主机是本地主机,因此我们需要确保可以通过 SSH 连接到本地主机并登录,而无需输入密码。

首先,确保已安装 SSH 并且服务器正在运行(我不确定这是什么意思)。例如,在 Ubuntu 上,这是通过以下方式实现的:

sudo  apt-get install ssh

然后,为了启用无密码登录,请使用空密码生成新的 SSH 密钥:

  ssh-keygen  -t  rsa -P  ''  -f  ~/.ssh/id_rsa
  cat ~/.ssh/id_rsa.pub   >>  ~/.ssh/authorized_keys

您可能还需要运行ssh 添加如果您正在运行 ssh-agent.Test,则可以连接:

  ssh localhost

如果成功,您就不必输入密码。

一切似乎都运行正常,但它仍然要求输入密码。我提供了我的登录密码,我也使用该密码进行 Root 访问。但它根本不起作用。请提出建议。

添加更多信息。我删除了旧密钥并添加了新密钥。

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

此后我的文件权限为

-rw-rw-r-- 1 incredible incredible  403 मई    24 17:16 authorized_keys
-rw------- 1 incredible incredible 1679 मई    23 23:08 id_rsa
-rw-r--r-- 1 incredible incredible  403 मई    23 23:08 id_rsa.pub
-rw-r--r-- 1 incredible incredible  444 मई    24 17:12 known_hosts

更改 Authorized_key 的权限后

-rw------- 1 incredible incredible  403 मई    24 17:16 authorized_keys
-rw------- 1 incredible incredible 1679 मई    23 23:08 id_rsa
-rw-r--r-- 1 incredible incredible  403 मई    23 23:08 id_rsa.pub
-rw-r--r-- 1 incredible incredible  444 मई    24 17:12 known_hosts

但即使这样,当我这样做时它仍然要求我输入密码ssh localhost

ssh -v localhost添加@heemayl 询问的更多信息输出

incredible@incredible:~$ ssh -v localhost OpenSSH_6.7p1 Ubuntu-5ubuntu1, 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 localhost [127.0.0.1] port 22. debug1: Connection established. debug1: identity file /home/incredible/.ssh/id_rsa type 1 debug1: key_load_public: No such file or directory debug1: identity file /home/incredible/.ssh/id_rsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/incredible/.ssh/id_dsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/incredible/.ssh/id_dsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/incredible/.ssh/id_ecdsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/incredible/.ssh/id_ecdsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/incredible/.ssh/id_ed25519 type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/incredible/.ssh/id_ed25519-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_6.7p1 Ubuntu-5ubuntu1 debug1: Remote protocol version 2.0, remote software version OpenSSH_6.7p1 Ubuntu-5ubuntu1 debug1: match: OpenSSH_6.7p1 Ubuntu-5ubuntu1 pat OpenSSH* 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 3c:e1:36:10:30:19:b3:e1:43:73:a5:6c:76:9e:24:67 debug1: Host 'localhost' is known and matches the ECDSA host key. debug1: Found key in /home/incredible/.ssh/known_hosts:1 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,password,keyboard-interactive debug1: Next authentication method: publickey debug1: Offering RSA public key: /home/incredible/.ssh/id_rsa debug1: Authentications that can continue: publickey,password,keyboard-interactive debug1: Trying private key: /home/incredible/.ssh/id_dsa debug1: Trying private key: /home/incredible/.ssh/id_ecdsa debug1: Trying private key: /home/incredible/.ssh/id_ed25519 debug1: Next authentication method: keyboard-interactive debug1: Authentications that can continue: publickey,password,keyboard-interactive debug1: Next authentication method: password incredible@localhost's password:

@heemayl : 以下是输出ssh -vvv localhost

debug1: Offering RSA public key: /home/incredible/.ssh/id_rsa debug3: send_pubkey_test debug2: we sent a publickey packet, wait for reply debug1: Authentications that can continue: publickey,password,keyboard-interactive debug1: Offering RSA public key: incredible@incredible debug3: send_pubkey_test debug2: we sent a publickey packet, wait for reply debug1: Authentications that can continue: publickey,password,keyboard-interactive debug1: Trying private key: /home/incredible/.ssh/id_dsa debug3: no such identity: /home/incredible/.ssh/id_dsa: No such file or directory debug1: Trying private key: /home/incredible/.ssh/id_ecdsa debug3: no such identity: /home/incredible/.ssh/id_ecdsa: No such file or directory debug1: Trying private key: /home/incredible/.ssh/id_ed25519 debug3: no such identity: /home/incredible/.ssh/id_ed25519: No such file or directory debug2: we did not send a packet, disable method debug3: authmethod_lookup keyboard-interactive debug3: remaining preferred: password debug3: authmethod_is_enabled keyboard-interactive debug1: Next authentication method: keyboard-interactive debug2: userauth_kbdint debug2: we sent a keyboard-interactive packet, wait for reply debug1: Authentications that can continue: publickey,password,keyboard-interactive debug3: userauth_kbdint: disable: no info_req_seen debug2: we did not send a packet, disable method debug3: authmethod_lookup password debug3: remaining preferred: debug3: authmethod_is_enabled password debug1: Next authentication method: password incredible@localhost's password:

答案1

该问题是由于文件的权限所致~/.ssh/authorized_keys。其权限不应该允许其他人写入该文件。

例如,如果权限设置为八进制666(这确实是魔鬼!!),由于您可以让所有其他人都拥有该文件的写权限~/.ssh/authorized_keys,因此该文件将被忽略,ssh并且会提示您输入密码。

假设该文件~/.ssh/authorized_keys事先不存在,则以下命令

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

~/.ssh/authorized_keys将使用您所指定的值确定的权限创建文件umask,然后附加文件的内容~/.ssh/id_rsa.pub

因此,解决方案是更改文件的权限,以便只有您可以写入,例如:

chmod 600 ~/.ssh/authorized_keys

相关内容