agent refused operation Permission denied (publickey) Error
异常及解决方案
错误描述 sign_and_send_pubkey: signing failed: agent refused operation
Permission denied (publickey)
当你在 Linux 电脑的终端下面通过 SSH 链接到 coding.net 或 github.com 时,你或许会看到如下代码:
sign_and_send_pubkey: signing failed: agent refused operation
Permission denied (publickey).
此时我们可以执行如下命令:
ssh -T git@git.coding.net
或者:
ssh -vT git@git.coding.net
我们或许将看到
OpenSSH_7.2p2 Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g 1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to git.coding.net [124.116.152.172] port 22.
debug1: Connection established.
......
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa
SHA256:jok3FH7q5LJ6qvE7iPNehBgXRw51ErE77S0Dn+Vg/Ik
debug1: Host 'git.coding.net' is known and matches the RSA host key.
debug1: Found key in /home/chen/.ssh/known_hosts:1
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
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/chen/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
sign_and_send_pubkey: signing failed: agent refused operation
debug1: Trying private key: /home/chen/.ssh/id_dsa
debug1: Trying private key: /home/chen/.ssh/id_ecdsa
debug1: Trying private key: /home/chen/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
解决办法通过 ssh-add
eval "$(ssh-agent -s)"
我们会看到:
Agent pid 25534
执行下面代码:
ssh-add
显示如下即成功:
Identity added: /home/chen/.ssh/id_rsa (/home/chen/.ssh/id_rsa)
如果你是多个公钥管理,你只需添加相应的文件,比如我在 bitbucket.org 下的公钥为 /home/chen/.ssh/bitbucket.id_rsa.pub 操作如下:
ssh-add /home/chen/.ssh/bitbucket.id_rsa.pub
ssh-add 命令详细介绍
语法
ssh-add [-cDdLlXx] [-t life] [file ...]
ssh-add -s pkcs11
ssh-add -e pkcs11
参数说明
-D :删除ssh-agent中的所有密钥;
-d :从ssh-agent中的删除密钥;
-e : pkcs11 :删除 PKCS#11 共享库 pkcs1 提供的钥匙;
-s : pkcs11 :添加 PKCS#11 共享库 pkcs1 提供的钥匙;
-L :显示 ssh-agent 中的公钥;
-l :显示 ssh-agent 中的密钥;
-t : life:对加载的密钥设置超时时间,超时 ssh-agent 将自动卸载密钥;
-X :对 ssh-agent 进行解锁;
-x :对 ssh-agent 进行加锁;
示例
把专用密钥添加到 ssh-agent 的高速缓存中
ssh-add /home/chen/.ssh/id_rsa
从ssh-agent中删除密钥
ssh-add -d /home/chen/.ssh/id_rsa.pub
查看ssh-agent中的密钥
ssh-add -l
fatal: refusing to merge unrelated histories
解决如下代码
git pull github master --allow-unrelated-histories
[陆续添加更新中]