macOS 升级到 10.12 后 ssh 私钥出问题了

2016-10-15 23:30:01 +08:00
 loser
test:~ test$ ssh -i /Users/test/key root@xxx.net
Enter passphrase for key '/Users/test/key':
Permission denied (publickey).
test:~ test$

好奇怪,之前都好好的,这几天升级了 os ,然后所有的服务器免 key 登陆都这样了,看起来是我的 key 出了问题,之前用 key 登陆也不需要密码可以直接上,查了 key 的文件时间也是 1 月份当时的。

而且我试过了所有密码都无法使用这个 key ,想哭
5017 次点击
所在节点    macOS
22 条回复
anguslg
2016-10-15 23:36:33 +08:00
公钥权限改成 500
shimanooo
2016-10-16 01:19:06 +08:00
dsa 还是 rsa 的? sierra 好像去掉了前者的支持。

ssh -vvv 看详情。
fx
2016-10-16 01:27:27 +08:00
我也是这样
fx
2016-10-16 01:27:59 +08:00
@shimanooo 这个怎么看
loser
2016-10-16 01:40:46 +08:00
@anguslg

test:~ test$ ssh -i /Users/test/key root@xxx.net
Enter passphrase for key '/Users/test/key':
Permission denied (publickey).
test:~ test$

依然如此。
shimanooo
2016-10-16 01:41:07 +08:00
打开公钥文件,看开头 ssh-dss 还是 ssh-rsa
shimanooo
2016-10-16 01:43:27 +08:00
loser
2016-10-16 01:44:10 +08:00
@shimanooo
加密是:
RSA PRIVATE KEY
AES-128-CBC

还有 ssh -vvv 是啥?没这个参数,有 -V
ssh -V
OpenSSH_7.2p2, LibreSSL 2.4.1
noli
2016-10-16 01:44:50 +08:00
先 ssh -v 看看是什么问题。
shimanooo
2016-10-16 01:46:21 +08:00
@loser
-v Verbose mode. Causes ssh to print debugging messages about its
progress. This is helpful in debugging connection, authentica-
tion, and configuration problems. Multiple -v options increase
the verbosity. The maximum is 3.
loser
2016-10-16 01:48:59 +08:00
test:~ test$ ssh -i /Users/test/test -p 2222 -v root@10.0.0.1
OpenSSH_7.2p2, LibreSSL 2.4.1
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: Connecting to 10.0.0.1 [10.0.0.1] port 2222.
debug1: Connection established.
debug1: identity file /Users/test/test type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/test/test-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5* compat 0x0c000000
debug1: Authenticating to 10.0.0.1:2222 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: diffie-hellman-group-exchange-sha256
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: aes128-ctr MAC: umac-64@openssh.com compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: umac-64@openssh.com compression: none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(2048<3072<8192) sent
debug1: got SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: got SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: ssh-rsa SHA256:bNuPwQRTJ6nM7QqHiU9DqrdaduA/MmgULzkjjW4UVeo
debug1: checking without port identifier
debug1: Host '10.0.0.1' is known and matches the RSA host key.
debug1: Found key in /Users/test/.ssh/known_hosts:47
debug1: found matching key w/out port
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/test/test
debug1: Server accepts key: pkalg ssh-rsa blen 279
Enter passphrase for key '/Users/test/test':
debug1: No more authentication methods to try.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

来了,各位大神
loser
2016-10-16 01:55:40 +08:00
如果真是 sierra 的问题,明天去公司用 windows 电脑拿这个 key 试试,不然就真的哭死了,一对服务器都是这个 key
noli
2016-10-16 02:33:23 +08:00
@loser 试试先把 test 这个 key 加入到 keychain 在使用。
ssh-add -K /Users/test/test
然后再用这个 private key 去 ssh
loser
2016-10-16 02:47:48 +08:00
@noli 谢谢
按您提示我 ssh-add 时需要这个 key 的密码,试过所有都不对,郁闷;可能太久远忘记了,明天换个 windows 机器拿这个 key 试试。

再次感谢。🙏
RqPS6rhmP3Nyn3Tm
2016-10-16 06:12:05 +08:00
我也出问题了,最后手动修改了 /etc/ssh/ssh_config 解决
tedd
2016-10-16 09:11:06 +08:00
顺便问问我如果要降级的话是不是把 ssh 文件夹拷贝出来,清盘降级后靠背回去就行呢?
laoyur
2016-10-16 09:44:18 +08:00
看上去并不是这个 key 本身出问题,而是你原先保存在 keychain 中的这个 key 的 passphrase 无法获取了,提示你输入 passphrase 时你又不记得,往这个方向搜索一下答案
laoyur
2016-10-16 09:58:14 +08:00
shutongxinq
2016-10-16 23:38:00 +08:00
"That ’ s expected. We re-aligned our behavior with the mainstream OpenSSH in this area.

You can fix this pretty easily by running ssh-add -A in your rc script if you want your keys to always be loaded."

Source: https://openradar.appspot.com/27348363
loser
2016-10-17 19:10:04 +08:00
谢谢 @laoyur @shutongxinq
我换 windows 后 ok 了, NND 还好把私钥的密码想起来了,真的吓哭。

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

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

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

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

© 2021 V2EX