SSH 免密钥登录, Mac 登录 VPS(Ubuntu)可以,登录另一个 Mac 始终失败

2022-11-24 01:38:04 +08:00
 youthfire
完全相同的公钥私钥操作流程
ssh-keygen -t rsa 后,公钥已经上传,且完成 chmod 目录 700 和密钥 600

连接一台远端 vps(ubuntu 22.04),一切正常,不再需要密钥
但连接本地局域网另一台 mbp ,始终要求输入密钥。server/client 都是 MacOs Monterey 12.6.1

求助!

tim@tim_s-mbp ~ % ssh -v hilary@hilarymac.local
OpenSSH_8.6p1, LibreSSL 3.3.6
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to hilarymac.local port 22.
debug1: Connection established.
debug1: identity file /Users/tim/.ssh/id_rsa type 0
debug1: identity file /Users/tim/.ssh/id_rsa-cert type -1
debug1: identity file /Users/tim/.ssh/id_dsa type -1
debug1: identity file /Users/tim/.ssh/id_dsa-cert type -1
debug1: identity file /Users/tim/.ssh/id_ecdsa type -1
debug1: identity file /Users/tim/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/tim/.ssh/id_ecdsa_sk type -1
debug1: identity file /Users/tim/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /Users/tim/.ssh/id_ed25519 type -1
debug1: identity file /Users/tim/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/tim/.ssh/id_ed25519_sk type -1
debug1: identity file /Users/tim/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /Users/tim/.ssh/id_xmss type -1
debug1: identity file /Users/tim/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.6
debug1: compat_banner: match: OpenSSH_8.6 pat OpenSSH* compat 0x04000000
debug1: Authenticating to hilarymac.local:22 as 'hilary'
debug1: load_hostkeys: fopen /Users/tim/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
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: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:xECOJFQQ3Rwk4Xg9QeD3yGZTE7ud71XhuBHGG/X0KPQ
debug1: load_hostkeys: fopen /Users/tim/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host 'hilarymac.local' is known and matches the ED25519 host key.
debug1: Found key in /Users/tim/.ssh/known_hosts:12
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /Users/tim/.ssh/id_rsa RSA SHA256:uQhIb4LRrWFgk1EXuSBggqhaUsaaJYgzXDODnB2k810 agent
debug1: Will attempt key: /Users/tim/.ssh/id_dsa
debug1: Will attempt key: /Users/tim/.ssh/id_ecdsa
debug1: Will attempt key: /Users/tim/.ssh/id_ecdsa_sk
debug1: Will attempt key: /Users/tim/.ssh/id_ed25519
debug1: Will attempt key: /Users/tim/.ssh/id_ed25519_sk
debug1: Will attempt key: /Users/tim/.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,sk-ssh-ed25519@openssh.com,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com,webauthn-sk-ecdsa-sha2-nistp256@openssh.com>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/tim/.ssh/id_rsa RSA SHA256:uQhIb4LRrWFgk1EXuSBggqhaUsaaJYgzXDODnB2k810 agent
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /Users/tim/.ssh/id_dsa
debug1: Trying private key: /Users/tim/.ssh/id_ecdsa
debug1: Trying private key: /Users/tim/.ssh/id_ecdsa_sk
debug1: Trying private key: /Users/tim/.ssh/id_ed25519
debug1: Trying private key: /Users/tim/.ssh/id_ed25519_sk
debug1: Trying private key: /Users/tim/.ssh/id_xmss
debug1: Next authentication method: keyboard-interactive
(hilary@hilarymac.local) Password:
2260 次点击
所在节点    VPS
31 条回复
Andreas8
2022-11-24 17:05:21 +08:00
Mac 要 add -k 我记得
PbCopy111
2022-11-25 09:43:19 +08:00
你的 mac 电脑,没有开启 key 登录模式。。。。
youthfire
2022-11-25 11:35:52 +08:00
@ETiV @tudou1514 谢谢帮助,试过了,都无效
我在 ssh -vvv 下,仔细看了过程,公钥 sent 正常,到私钥这步显示 debug2: we did not send a packet, disable method 。我按照网上资料,一般或者是因为权限,或者是因为 authorized_keys 内有错误,都检查了

@PbCopy111 求教 Mac 哪里查看是不是开启了 key 登录模式?
PbCopy111
2022-11-25 12:20:10 +08:00
vi /etc/ssh/sshd_config

RSAAuthentication yes
PubkeyAuthentication yes

这个开了没有?
@youthfire #23
youthfire
2022-11-25 14:54:50 +08:00
@PbCopy111 谢谢指导。我的理解是你指 remote 端 mac 这样改是吧,为防止出错,我两台 mac 都改了。已经 PubkeyAuthentication yes 。 没有添加 RSAAuthentication yes ,因为用的 ed25519 。然后 remote login off, remote login on (相当于重启了 hhd),目前还是没效果。

tim@timmac ~ % ssh -Tvv hilary@hilarymac.local
OpenSSH_8.6p1, LibreSSL 3.3.6
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to hilarymac.local port 22.
debug1: Connection established.
debug1: identity file /Users/tim/.ssh/id_rsa type -1
debug1: identity file /Users/tim/.ssh/id_rsa-cert type -1
debug1: identity file /Users/tim/.ssh/id_dsa type -1
debug1: identity file /Users/tim/.ssh/id_dsa-cert type -1
debug1: identity file /Users/tim/.ssh/id_ecdsa type -1
debug1: identity file /Users/tim/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/tim/.ssh/id_ecdsa_sk type -1
debug1: identity file /Users/tim/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /Users/tim/.ssh/id_ed25519 type 3
debug1: identity file /Users/tim/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/tim/.ssh/id_ed25519_sk type -1
debug1: identity file /Users/tim/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /Users/tim/.ssh/id_xmss type -1
debug1: identity file /Users/tim/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.6
debug1: compat_banner: match: OpenSSH_8.6 pat OpenSSH* compat 0x04000000
debug1: Authenticating to hilarymac.local:22 as 'hilary'
debug1: load_hostkeys: fopen /Users/tim/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,ext-info-c
debug2: host key algorithms: ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: MACs ctos: 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: MACs stoc: 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: compression ctos: none,zlib@openssh.com,zlib
debug2: compression stoc: none,zlib@openssh.com,zlib
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256
debug2: host key algorithms: rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: MACs ctos: 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: MACs stoc: 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: compression ctos: none,zlib@openssh.com
debug2: compression stoc: none,zlib@openssh.com
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
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: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:xECOJFQQ3Rwk4Xg9QeD3yGZTE7ud71XhuBHGG/X0KPQ
debug1: load_hostkeys: fopen /Users/tim/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host 'hilarymac.local' is known and matches the ED25519 host key.
debug1: Found key in /Users/tim/.ssh/known_hosts:12
debug2: set_newkeys: mode 1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /Users/tim/.ssh/id_rsa
debug1: Will attempt key: /Users/tim/.ssh/id_dsa
debug1: Will attempt key: /Users/tim/.ssh/id_ecdsa
debug1: Will attempt key: /Users/tim/.ssh/id_ecdsa_sk
debug1: Will attempt key: /Users/tim/.ssh/id_ed25519 ED25519 SHA256:wJbU+P+mASkQNm/g1cd+a8vRc/81sULbFgqzk7buPj8
debug1: Will attempt key: /Users/tim/.ssh/id_ed25519_sk
debug1: Will attempt key: /Users/tim/.ssh/id_xmss
debug2: pubkey_prepare: done
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,sk-ssh-ed25519@openssh.com,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com,webauthn-sk-ecdsa-sha2-nistp256@openssh.com>
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/tim/.ssh/id_rsa
debug1: Trying private key: /Users/tim/.ssh/id_dsa
debug1: Trying private key: /Users/tim/.ssh/id_ecdsa
debug1: Trying private key: /Users/tim/.ssh/id_ecdsa_sk
debug1: Offering public key: /Users/tim/.ssh/id_ed25519 ED25519 SHA256:wJbU+P+mASkQNm/g1cd+a8vRc/81sULbFgqzk7buPj8
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /Users/tim/.ssh/id_ed25519_sk
debug1: Trying private key: /Users/tim/.ssh/id_xmss
debug2: we did not send a packet, disable method
debug1: Next authentication method: keyboard-interactive
debug2: userauth_kbdint
debug2: we sent a keyboard-interactive packet, wait for reply
debug2: input_userauth_info_req: entering
debug2: input_userauth_info_req: num_prompts 1
(hilary@hilarymac.local) Password:
ETiV
2022-11-25 18:58:49 +08:00
还没解决呐 😂
emmitt
2022-11-25 22:26:20 +08:00
先看 sshd 日志,再检查 key 权限
youthfire
2022-11-26 00:04:38 +08:00
@ETiV 上面大家提到的,但凡认知范围内,能操作的都操作了,剩下的就是没有看服务器端日志,主要是我不清楚怎么看是正确的,又怕大家觉得我伸手党,搜了大半天,进展慢。

google 到的资料有说看 var/log/system.log ,我看了就 2 行,如下。似乎并没有什么帮助
Nov 25 23:42:10 hilary_s-mbp sshd: hilary [priv][7893]: USER_PROCESS: 7896 ttys000
Nov 25 23:42:14 hilary_s-mbp sshd: hilary [priv][7893]: DEAD_PROCESS: 7896 ttys000

也有说去 /etc/ssh/sshd_config 打开 LogLevel VERBOSE 。 我打开 sshd_config 并没有发现 LogLevel 字眼。是直接添加“LogLevel VERBOSE” 吗?然后去哪里看,system.log 吗?毫无概念

同时也有说,用 ssh -Tvv ,确实如 25 楼结果,显示了更详细的 debug2 。特意去查了“we did not send a packet, disable method”,如 23 楼时所示,无所收获

看了 2 天,基本把可能造成的十来种可能性都看了,又感觉都是 linux 解决方案,而我的 ubuntu remote 机上本身就很顺利。感觉 mac 作为 remote 是一个另类,当然主要还是我的知识有限。
dzdh
2022-11-28 09:31:17 +08:00
服务端把 sshd 停掉

手动 /sbin/sshd -D 看日志
Mmahaha
86 天前
同样的问题,怎么改配置重启都不行,楼主最后解决了吗?
youthfire
85 天前
@Mmahaha 可能 mac 系统的问题,我有三台 mac 目标机,两台可以,一台不行。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/897479

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX