macos - 设置无密码 ssh

标签 macos ssh remote-access

我试图在 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).

我查看了谷歌并找到了类似的帖子。我提到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

原来的问题没有解决。有另一个帖子提到执行命令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

检查远程登录

enter image description here

我调试并获取信息,
$ 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

key 生成如下,
ssh-keygen -t rsa

这里错过了什么?

笔记

我找到了另一种生成 key 的方法,
ssh-keygen -t dsa -P ” -f ~/.ssh/id_dsa

我应该试试这个方法吗?

最佳答案

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

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

关于macos - 设置无密码 ssh,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51836719/

相关文章:

macos - 在 Inline::C 中链接 macOS 的框架

macos - 使用 ssh-keygen 创建 JSch 接受的 SSH 私钥

git - Docker:如何使用 ssh 访问私有(private) github 存储库?

amazon-web-services - 有没有办法提高亚马逊aws上的sshfs速度?

iphone - 如何处理iphone中的按键事件

macos - Docker:MacOS 向主机公开容器端口

macos - 如何使用 Homebrew 在 Mac OSX 上安装 PerlMagick?

git - 克隆项目时权限被拒绝

php - 如何从本地mysql更新数据到远程mysql服务器?

c - 如何使用可以远程连接的控制台创建 linux C 应用程序