macOS 升级到 10.12 后 ssh 私钥出问题了 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
loser
V2EX    macOS

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

  •  
  •   loser 2016-10-15 23:30:01 +08:00 5569 次点击
    这是一个创建于 3294 天前的主题,其中的信息可能已经有所发展或是发生改变。
    test:~ test$ ssh -i /Users/test/key [email protected]
    Enter passphrase for key '/Users/test/key':
    Permission denied (pblickey).
    test:~ test$

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

    而且我试过了所有密码都无法使用这个 key ,想哭
    第 1 条附言    2016-10-17 19:15:11 +08:00
    把私钥丢到 windows 系统上, putty 上去了。
    有点惊险。
    22 条回复    2019-03-10 15:33:42 +08:00
    anguslg
        1
    anguslg  
       2016-10-15 23:36:33 +08:00
    公钥权限改成 500
    shimanooo
        2
    shimanooo  
       2016-10-16 01:19:06 +08:00 via iPad
    dsa 还是 rsa 的? sierra 好像去掉了前者的支持。

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

    test:~ test$ ssh -i /Users/test/key [email protected]
    Enter passphrase for key '/Users/test/key':
    Permission denied (publickey).
    test:~ test$

    依然如此。
    shimanooo
        6
    shimanooo  
       2016-10-16 01:41:07 +08:00
    打开公钥文件,看开头 ssh-dss 还是 ssh-rsa
    shimanooo
        7
    shimanooo  
       2016-10-16 01:43:27 +08:00
    loser
        8
    loser  
    OP
       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
        9
    noli  
       2016-10-16 01:44:50 +08:00
    先 ssh -v 看看是什么问题。
    shimanooo
        10
    shimanooo  
       2016-10-16 01:46:21 +08:00   1
    @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
        11
    loser  
    OP
       2016-10-16 01:48:59 +08:00
    test:~ test$ ssh -i /Users/test/test -p 2222 -v [email protected]
    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: [email protected] compression: none
    debug1: kex: client->server cipher: aes128-ctr MAC: [email protected] 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
        12
    loser  
    OP
       2016-10-16 01:55:40 +08:00
    如果真是 sierra 的问题,明天去公司用 windows 电脑拿这个 key 试试,不然就真的哭死了,一对服务器都是这个 key
    noli
        13
    noli  
       2016-10-16 02:33:23 +08:00
    @loser 试试先把 test 这个 key 加入到 keychain 在使用。
    ssh-add -K /Users/test/test
    然后再用这个 private key 去 ssh
    loser
        14
    loser  
    OP
       2016-10-16 02:47:48 +08:00
    @noli 谢谢
    按您提示我 ssh-add 时需要这个 key 的密码,试过所有都不对,郁闷;可能太久远忘记了,明天换个 windows 机器拿这个 key 试试。

    再次感谢。
    RqPS6rhmP3Nyn3Tm
        15
    RqPS6rhmP3Nyn3Tm  
       2016-10-16 06:12:05 +08:00
    我也出问题了,最后手动修改了 /etc/ssh/ssh_config 解决
    tedd
        16
    tedd  
       2016-10-16 09:11:06 +08:00 via iPhone
    顺便问问我如果要降级的话是不是把 ssh 文件夹拷贝出来,清盘降级后靠背回去就行呢?
    laoyur
        17
    laoyur  
       2016-10-16 09:44:18 +08:00
    看上去并不是这个 key 本身出问题,而是你原先保存在 keychain 中的这个 key 的 passphrase 无法获取了,提示你输入 passphrase 时你又不记得,往这个方向搜索一下答案
    laoyur
        18
    laoyur  
       2016-10-16 09:58:14 +08:00
    shutongxinq
        19
    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
        20
    loser  
    OP
       2016-10-17 19:10:04 +08:00
    谢谢 @laoyur @shutongxinq
    我换 windows 后 ok 了, NND 还好把私钥的密码想起来了,真的吓哭。
    moro
        21
    moro  
       2016-12-19 17:09:48 +08:00
    @BXIA 请教一下,修改哪些参数可以解决呢。
    zhang330700
        22
    zhang330700  
       2019-03-10 15:33:42 +08:00
    我的情况是
    修改 /etc/ssh/ssh_config 和 /etc/ssh/sshd_config 的配置 ,支持 dss 格式的秘钥,
    PubkeyAcceptedKeyTypes=+ssh-dss
    ForwardAgent yes
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     3650 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 28ms UTC 00:49 PVG 08:49 LAX 17:49 JFK 20:49
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86