git添加遇到问题 sign_and_send_pubkey: signing failed: agent refused operation Permission denied (publicke...

Sahar ·
更新时间:2024-11-14
· 868 次阅读

sign_and_send_pubkey: signing failed: agent refused operation Permission denied (publickey). 参考

https://help.github.com/cn/github/authenticating-to-github/error-permission-denied-publickey

https://segmentfault.com/a/1190000008733238

https://www.cnblogs.com/mozq/p/11824468.html

步骤 ssh-keygen -t rsa -C "xxxxx@xx.com"

 在本地生成 rsa 公私钥。直接回车。名称必须是默认的id_rsa

 将公钥保存到 github / gitee

ssh -T git@github.com

如果正常会返回

Hi XXX! You've successfully authenticated 之类的

当然我们这里遇到的是

sign_and_send_pubkey: signing failed: agent refused operation Permission denied (publickey).

此时我们可以执行如下命令:

ssh -vT git@github.com

如果看到以下Permission denied (publickey) 结尾

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 xxxxx

继续执行

ssh-add

显示如下即成功:

Identity added: /home/xxx/.ssh/id_rsa (/home/xxx/.ssh/id_rsa)
作者:clemente620



agent send AND Git sign

需要 登录 后方可回复, 如果你还没有账号请 注册新账号