第一次使用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也不会出现连不上的问题。
|