无法在 Mac OS El Capitan 上 ssh localhost
Posted
技术标签:
【中文标题】无法在 Mac OS El Capitan 上 ssh localhost【英文标题】:Unable to ssh localhost on Mac OS El Capitan 【发布时间】:2016-09-19 12:29:24 【问题描述】:我在尝试建立 ssh localhost 连接时遇到了一些麻烦。我想在没有密码的情况下执行此操作,因此当我创建公钥/私钥对时,当要求输入密码时,我输入了返回键,如图所示。 当我尝试命令时
ssh localhost
我仍然被要求输入密码。所以我认为问题可能来自一些参数,避免没有密码的公钥,我创建了一个带有密码的新公钥/私钥对。但是,我仍然收到以下消息:
Failing ssh to localhost : Permission denied (publickey,keyboard-interactive).
有关信息,我使用命令创建了密钥对:
ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
在做了一些研究之后,我了解到错误的权限会导致问题,所以这里是命令 ls -lha ~/.ssh/ 的结果:
drwx------ 7 matthieu staff 238B 22 mai 17:50 .
drwxr-xr-x+ 35 matthieu staff 1,2K 22 mai 17:52 ..
-rw-r--r-- 1 matthieu staff 612B 22 mai 17:50 authorized_keys
-rw------- 1 matthieu staff 672B 22 mai 17:49 id_dsa
-rw-r--r-- 1 matthieu staff 612B 22 mai 17:49 id_dsa.pub
-rw-r--r-- 1 matthieu staff 171B 22 mai 10:00 known_hosts
我还在详细模式下运行 ssh (ssh -vvv localhost),它给出:
OpenSSH_6.9p1, LibreSSL 2.1.8
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to localhost [::1] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /Users/matthieu/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/matthieu/.ssh/id_rsa-cert type -1
debug1: identity file /Users/matthieu/.ssh/id_dsa type 2
debug1: key_load_public: No such file or directory
debug1: identity file /Users/matthieu/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/matthieu/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/matthieu/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/matthieu/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/matthieu/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.9
debug1: match: OpenSSH_6.9 pat OpenSSH* compat 0x04000000
debug2: fd 5 setting O_NONBLOCK
debug1: Authenticating to localhost:22 as 'matthieu'
debug3: hostkeys_foreach: reading file "/Users/matthieu/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /Users/matthieu/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from localhost
debug3: order_hostkeyalgs: prefer hostkeyalgs: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-dss-cert-v00@openssh.com,ssh-ed25519,ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1,hmac-md5-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1,hmac-md5-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ssh-ed25519
debug2: kex_parse_kexinit: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: kex_parse_kexinit: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug1: kex: server->client chacha20-poly1305@openssh.com <implicit> none
debug1: kex: client->server chacha20-poly1305@openssh.com <implicit> none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:A9YQlWJMyCIXIan+dT/wB4qYxQaJP7Z+fovz+88JDEg
debug3: hostkeys_foreach: reading file "/Users/matthieu/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /Users/matthieu/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from localhost
debug1: Host 'localhost' is known and matches the ECDSA host key.
debug1: Found key in /Users/matthieu/.ssh/known_hosts:1
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /Users/matthieu/.ssh/id_dsa (0x7fd3f0d13f70),
debug2: key: /Users/matthieu/.ssh/id_rsa (0x0),
debug2: key: /Users/matthieu/.ssh/id_ecdsa (0x0),
debug2: key: /Users/matthieu/.ssh/id_ed25519 (0x0),
debug1: Authentications that can continue: publickey,keyboard-interactive
debug3: start over, passed a different list publickey,keyboard-interactive
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering DSA public key: /Users/matthieu/.ssh/id_dsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Trying private key: /Users/matthieu/.ssh/id_rsa
debug3: no such identity: /Users/matthieu/.ssh/id_rsa: No such file or directory
debug1: Trying private key: /Users/matthieu/.ssh/id_ecdsa
debug3: no such identity: /Users/matthieu/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /Users/matthieu/.ssh/id_ed25519
debug3: no such identity: /Users/matthieu/.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
debug2: input_userauth_info_req
debug2: input_userauth_info_req: num_prompts 1
Password:
debug1: Authentications that can continue: publickey,keyboard-interactive
debug2: userauth_kbdint
debug2: we sent a keyboard-interactive packet, wait for reply
debug2: input_userauth_info_req
debug2: input_userauth_info_req: num_prompts 1
Password:
debug1: Authentications that can continue: publickey,keyboard-interactive
debug2: userauth_kbdint
debug2: we sent a keyboard-interactive packet, wait for reply
debug2: input_userauth_info_req
debug2: input_userauth_info_req: num_prompts 1
Password:
debug1: Authentications that can continue: publickey,keyboard-interactive
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey,keyboard-interactive).
有一个朋友和我有相同的笔记本电脑(最后一个 mbp Retina 13"),与他一起 ssh localhost 工作正常,我注意到他在执行 ssh -vvv localhost 时在开头有额外的行:
OpenSSH_6.9p1, LibreSSL 2.1.8
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: /etc/ssh/ssh_config line 56: Applying options for *
为了记录,我已经检查了这些页面并尝试了建议的内容,但没有成功: SSH: "Bad passphrase" after generation of public key 和 ssh: Permission denied (publickey,keyboard-interactive) 提前感谢您提供任何建议、想法或解决方案
【问题讨论】:
【参考方案1】:您可以尝试使用特定的密钥进行授权:
ssh localhost -i ~/.ssh/id_dsa
如果成功,则可以将其添加到 ~/.ssh/config 的 ssh 配置文件中。 如果不存在这样的文件,只需通过 touch 或 vi 创建即可。
配置应如下所示,请相应修改:
Host localhost
HostName 127.0.0.1
Port 22
user matthieu
IdentityFile ~/.ssh/id_dsa
祝你好运!
【讨论】:
【参考方案2】:来自sshd(8)
的手册页:
~/.ssh/authorized_keys
文件内容不高度敏感,但推荐权限为用户读/写,其他人不可访问。
您会在服务器日志中找到关于不使用您的authorized_keys
的信息,因为它的权限太宽。您应该将权限更改为只能由您读写:chmod 600 ~/.ssh.authorized_keys
【讨论】:
我刚做了,同样的行为:它要求输入密码,并拒绝连接。 然后检查服务器端日志。密钥被拒绝。【参考方案3】:我在使用 dsa 密钥时遇到了同样的问题,因此尝试使用 rsa 密钥,它工作正常。要生成 rsa 密钥,只需将 -t 标志更改为 '-t rsa'。
【讨论】:
【参考方案4】:我遵循问题中以及上述回复中提到的相同流程,根本无法让它接受无密码登录。
以下步骤为我解决了这个问题,我怀疑真正的关键是在运行:$ eval `ssh-agent`
20:05:43 ✔ /etc :: ssh localhost
Password:
20:05:51 ✘ /etc :: eval `ssh-agent`
Agent pid 38262
20:07:44 ✔ /etc :: ssh-add ~/.ssh/id_rsa
Identity added: /Users/tallamjr/.ssh/id_rsa tallamjr@Tareks-MacBook-Pro.local
20:07:58 ✔ /etc :: ssh-add -l
2048 SHA256:-------------HASH------------- tallamjr@Tareks-MacBook-Pro.local (RSA)
20:08:18 ✔ /etc :: ssh-keygen -l -f ~/.ssh/id_rsa.pub
2048 SHA256:-----------SAME-HASH---------- tallamjr@Tareks-MacBook-Pro.local (RSA)
20:08:29 ✔ /etc :: ssh-copy-id -i ~/.ssh/id_rsa.pub tallamjr@localhost
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/tallamjr/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'tallamjr@localhost'"
and check to make sure that only the key(s) you wanted were added.
20:09:39 ✔ /etc :: ssh tallamjr@localhost
Last login: Thu Jan 23 20:05:37 2020 from ::1
20:09:57 ✔ ~ :: exit
logout
Connection to localhost closed.
20:09:59 ✔ /etc :: ssh localhost
Last login: Thu Jan 23 20:09:52 2020 from ::1
REF:灵感来自here的步骤
【讨论】:
以上是关于无法在 Mac OS El Capitan 上 ssh localhost的主要内容,如果未能解决你的问题,请参考以下文章
在 Mac OS X El Capitan 10.11.4 上安装 MySQL 5.7
在 Mac OS X Yosemite/El Capitan 上自动启动 MySQL 服务器
在 Mac OS X 10.11.6 El Capitan 上安装 ffmpeg 时出现问题 [关闭]
在 Mac OS X El Capitan 上使用 xlwings 打开 Excel 文件需要弹出授予访问权限