git@gitee.com: Permission denied (publickey).

第一次使用git工具,按照gitee官网教程设置完密钥 ,重启以后再次ssh,出现错误

# ssh -T git@gitee.com
git@gitee.com: Permission denied (publickey).

查了网上资料,说是要先启动ssh-agent,然后运行ssh-add,将git仓库设置的公钥对应的私钥添加

#ssh-add /root/.ssh/id_rsa_git 设置完果然有用,高兴之时发现重启后又失效了!

细心的网友可能会发现我的私钥文件名不是默认的id_rsa,这是因为我的id_rsa这个私钥文件是用来登陆我自己 远程服务器设置的,生成git密钥对的时候不想覆盖,所以设置了一个新名字,问题恰恰可能就出现这个名字上面。

man ssh看看

-F configfile
             Specifies an alternative per-user configuration file.  If a con‐
             figuration file is given on the command line, the system-wide
             configuration file (/etc/ssh/ssh_config) will be ignored.  The
             default for the per-user configuration file is ~/.ssh/config.

找到这么一段,有个ssh_config文件?赶紧去目录找找,在/etc/ssh/找到了

# Host *
#   ForwardAgent no
#   ForwardX11 no
#   PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   GSSAPIKeyExchange no
#   GSSAPITrustDNS no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   IdentityFile ~/.ssh/id_ecdsa
#   IdentityFile ~/.ssh/id_ed25519
#   Port 22
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
#   MACs hmac-md5,hmac-sha1,umac-64@openssh.com
#   EscapeChar ~
#   Tunnel no

 这大概是个模板,需要把这个文件另存到/root/.ssh/目录下,名字改为config

Host gitee.com 
#   ForwardAgent no
#   ForwardX11 no
#   PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   GSSAPIKeyExchange no
#   GSSAPITrustDNS no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   IdentityFile ~/.ssh/id_ecdsa
#   IdentityFile ~/.ssh/id_ed25519
   IdentityFile ~/.ssh/id_rsa_git 
#   Port 22
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
#   MACs hmac-md5,hmac-sha1,umac-64@openssh.com

 在host填入gitee.com,下面指定私钥文件路径,再次运行ssh -T git@gitee.com

# ssh -T git@gitee.com
H! You've successfully authenticated, but GITEE.COM does not provide shell access.

成功。并且重启也还是ok的,包括git push也不会出现连不上的问题。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值