“ssh-add -d”拒絕刪除身份

“ssh-add -d”拒絕刪除身份

為了忘記私鑰密碼(id_rsa),我通常運行:

ssh-add -D # to forget all loaded identities
ssh-add -d # to forget primary identity ($HOME/.ssh/id_rsa)

現在使用 macOS Sierra v10.12.1 我收到此錯誤:

$ ssh-add -D
All identities removed.
$ ssh-add -d
Could not remove identity "/Users/user/.ssh/id_rsa": agent refused operation
Could not remove identity "/Users/user/.ssh/id_dsa": agent refused operation

我搜尋谷歌沒有運氣!

答案1

我和塞拉也有同樣的問題。嘗試刪除id_rsa然後$HOME/.ssh/重新啟動(我id_rsa.pub也刪除了 - 因此兩個鍵私人的民眾)。它解決了我的問題。

答案2

就我而言,我遇到了一個稍微不同的問題。當我呼叫ssh-add -D代理時,它似乎成功並做出回應All identities removed.,但實際上,在列出代理金鑰時,ssh-add -l不需要的金鑰仍然列出,當然,當嘗試使用代理對遠端主機進行身份驗證時,代理會提示我使用我配置的pin 程式將密碼短語設定為不需要的金鑰。惱人的。

問題的原因是我的 gpg-agent 守護程式已將金鑰快取在路徑下的檔案中~/.gnupg/sshcontrol

$ cat ~/.gnupg/sshcontrol
# List of allowed ssh keys.  Only keys present in this file are used
# in the SSH protocol.  The ssh-add tool may add new entries to this
# file to enable them; you may also add them manually.  Comment
# lines, like this one, as well as empty lines are ignored.  Lines do
# have a certain length limit but this is not serious limitation as
# the format of the entries is fixed and checked by gpg-agent. A
# non-comment line starts with optional white spaces, followed by the
# keygrip of the key given as 40 hex digits, optionally followed by a
# caching TTL in seconds, and another optional field for arbitrary
# flags.   Prepend the keygrip with an '!' mark to disable it.

# RSA key added on: 2021-06-03 16:23:25
# Fingerprints:  MD5:c1:[elided]:24
#                SHA256:+Mj[elided]E4
21[elided]C9 0
# Ed25519 key added on: 2021-06-03 22:11:36
# Fingerprints:  MD5:[elided]:24:da
#                SHA256:EL[elided]Zs
E0[elided]47 0

從 中刪除這些金鑰~/.gnupg/sshcontrol可讓我恢復使用 gpg-agent 來對遠端主機進行身份驗證,而無需代理程式要求我不再使用的金鑰的密碼。

答案3

當引用的身份與添加的身份不同時,我就發生了這個錯誤。該-d選項刪除特定的鍵。如果該密鑰從未加載過,它將拒絕刪除它。您可以檢查載入的金鑰ssh-add -l並檢查金鑰簽名ssh-keygen -lf <path-to-private-key>

答案4

我發現Ubuntu 18.04仍然有這個bug。

這是我從 ssh-agent 中刪除不需要的金鑰的簡單方法,無需任何重大努力:

  1. 找到您要刪除的密鑰

    ssh-add -l
    2048 SHA256:qzJYF7AJAJsLsJn7ZFPcJ+w78ZJVoPZI9TzXCq2cf5 .ssh/bad-key.pem (RSA)
    
  2. 進入 ~/.ssh 目錄並建立子目錄,例如名為“disabled”

    cd ~/.ssh
    mkdir disabled
    
  3. 將要停用的密鑰移到該目錄中。

    mv bad-key.pem disabled/
    

就是這樣。該密鑰在 ssh-agent 中應該不再可用,但您仍然可以擁有它並在需要時將其添加回來。

相關內容