跳到主要内容
ecdsa.com
OpenSSH (ssh-keygen, ssh-add, ssh)SSH

错误信息

Load key "/path/to/key": incorrect passphrase supplied to decrypt private key

也可能输出为

  • incorrect passphrase supplied to decrypt private key
  • Bad passphrase, try again for /path/to/key:

交互式的 `ssh-add` 会用“Bad passphrase, try again for …:”再次询问;`ssh` 本身只是再次提示输入。

OpenSSH (ssh-keygen, ssh-add, ssh) — encrypted private key

含义

密钥文件解析正常,而且是加密的;用你提供的密码短语解密失败。OpenSSH 能把这种情况与文件损坏区分开,因为加密容器中带有校验值——所以这条消息确实意味着“密码短语错误”,对 OpenSSH 格式的密钥和加密的 PEM/PKCS#8 密钥都是如此。忘记的密码短语无法找回,只能更换密钥。

原因

修复方法

  1. 1.

    以交互方式测试密码短语

    如果 `ssh-keygen -y` 接受你手动输入的密码短语,问题就出在脚本传入密码短语的方式上。

    bash
    ssh-keygen -y -f ~/.ssh/id_ed25519 > /dev/null   # prompts; succeeds only with the right passphrase
    ssh-keygen -p -f ~/.ssh/id_ed25519                # change the passphrase (needs the old one)
  2. 2.

    用 SSH 代理代替传递密码短语

    在 `ssh-agent`(或操作系统钥匙串)中解锁一次密钥,而不是把密码短语写进脚本或 CI。

    bash
    # Unlock once per session instead of typing or storing the passphrase in scripts
    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/id_ed25519
    # macOS: keep it in the keychain
    ssh-add --apple-use-keychain ~/.ssh/id_ed25519

相关错误

浏览完整的签名错误库