设置无密码 ssh

Setup passphraseless ssh

我试图在 Mac OS 中 运行 Hadoop,但出现以下错误,

$ hstart


WARNING: Attempting to start all Apache Hadoop daemons as chaklader in 10 seconds.
WARNING: This is not a recommended production deployment configuration.
WARNING: Use CTRL-C to abort.
Starting namenodes on [localhost]
localhost: Permission denied (publickey,password,keyboard-interactive).
Starting datanodes
localhost: Permission denied (publickey,password,keyboard-interactive).
Starting secondary namenodes [macs-MacBook-Pro.local]
macs-MacBook-Pro.local: Permission denied (publickey,password,keyboard-interactive).
2018-08-14 13:59:34,949 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Starting resourcemanager
Starting nodemanagers
localhost: Permission denied (publickey,password,keyboard-interactive).

我查看了 Google 并找到了一个类似的 post。我提到 Permission denied 是错误,我没有正确设置 passwordless ssh。例如,ssh localhost 不应要求输入密码。

我 运行 ssh localhost 它确实要求输入密码。作为问题的解决方案,提到执行命令,

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

我这样做了,然后当我 运行 ssh localhost 时,我被要求输入 passphrase(而不是密码)。

$ ssh localhost

Enter passphrase for key '/Users/chaklader/.ssh/id_rsa': 
Last login: Tue Aug 14 14:03:30 2018 from ::1

原问题没有解决。还有另一个 post 提到执行命令 chmod og-wx ~/.ssh/authorized_keys 并且在我这样做之后,它仍然保持不变。

我试图检查 id_rsa 里面的内容并找到信息,

$ cat ~/.ssh/id_rsa.pub
ssh-rsa 

AAAAB3NzaC1yc2EAAAADAQABAAABAQDB/1Ryk4mB2/9rxpvF21JWKBOyx+hgo572zp9ZNcLmj1FcNN9saJ0AfYcmkILowEoCKgzOCbAvapd+JsPomPMsuKD37AGvfF88YWAjKPYOg3wo5JMwIp/CEyk349satGWUy+Q99288iJcS5NKkhLEN1bMOyIpgbFFxmpCdFXNSl9UfeCN4oyndWJzmnHkI6C9mu4BWibcW3PkKkwI2HVPop14m3jRjHJvmwGzRQxp/bjUVRqSZ52KTuVMYRrCsKdd048tBHOK0ujjshpBCoedtFoXt3xP0B78WZyvgFr2Pj9DrgdFI+T7gkJUv4xbmtKfCOZR7yFVwoUtgAF5k/FC1 chaklader@macs-MacBook-Pro.local


$ cat ~/.ssh/authorized_keys 
ssh-rsa 

AAAAB3NzaC1yc2EAAAADAQABAAABAQDB/1Ryk4mB2/9rxpvF21JWKBOyx+hgo572zp9ZNcLmj1FcNN9saJ0AfYcmkILowEoCKgzOCbAvapd+JsPomPMsuKD37AGvfF88YWAjKPYOg3wo5JMwIp/CEyk349satGWUy+Q99288iJcS5NKkhLEN1bMOyIpgbFFxmpCdFXNSl9UfeCN4oyndWJzmnHkI6C9mu4BWibcW3PkKkwI2HVPop14m3jRjHJvmwGzRQxp/bjUVRqSZ52KTuVMYRrCsKdd048tBHOK0ujjshpBCoedtFoXt3xP0B78WZyvgFr2Pj9DrgdFI+T7gkJUv4xbmtKfCOZR7yFVwoUtgAF5k/FC1 chaklader@macs-MacBook-Pro.local

勾选远程登录

我调试并获取了信息,

$ ssh -v localhost

OpenSSH_7.5p1, LibreSSL 2.5.4
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 52: Applying options for *
debug1: Connecting to localhost [::1] port 22.
debug1: Connection established.
debug1: identity file /Users/chaklader/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/chaklader/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/chaklader/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/chaklader/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/chaklader/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/chaklader/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/chaklader/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/chaklader/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.5
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.5
debug1: match: OpenSSH_7.5 pat OpenSSH* compat 0x04000000
debug1: Authenticating to localhost:22 as 'chaklader'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:R9cek2xWHJN6rgvBKr4JZMKisZbifnxvPoSzIb5z5Ik
debug1: Host 'localhost' is known and matches the ECDSA host key.
debug1: Found key in /Users/chaklader/.ssh/known_hosts:2
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
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: /Users/chaklader/.ssh/id_rsa
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279

密钥生成如下,

ssh-keygen -t rsa

这里遗漏了什么?

备注

我找到了另一种生成密钥的方法,

ssh-keygen -t dsa -P ” -f ~/.ssh/id_dsa

我应该试试这个方法吗?

当然,在 RSA 密钥上使用密码的优点是,如果有人以某种方式获得您的私钥(密码应防止他们使用它),它会为您提供一些保护。虽然这是个好主意,但它违背了 'passwordless' ssh 登录的目的。如果每次使用密钥时都必须输入密码短语,那么人们会争论说它不完全是无密码的。如果有人能够访问私钥,您可能会认为他们可以完全访问私钥所在的机器,或者您对私钥不小心。

有一些'safeguarding' measures关于私钥你可以考虑;真正最重要的是只在需要的地方保留私钥,而不是将它们放在您的机器周围。