和【git】如何在git本地配置多个SSH keys这篇有点类似
1、先设置git账户信息
git config --global user.name "Git账号"
git config --global user.email "Git邮箱"
2、生成一个SSH密钥
ssh-keygen -t rsa -C "your_email@example.com"
拷贝私钥地址,等会需要用到
3、使用git bash将ssh私钥添加到ssh-agent
这也是和mac不同的地方
启动ssh-agent
eval $(ssh-agent -s)
将ssh私钥添加到ssh-agent
ssh-add /C/Users/xx/.ssh/id_rsa
4、将公钥添加到github账户
5、测试链接
ssh -T git@github.com
发现报这个错误
搜索了下发现是开了全局代理,关闭就好了。但是能不能不关闭全局代理呢.在C:\Users\xx\.ssh\config里面添加下面的配置,就是更改了端口:22->443和HostName: github.com->ssh.github.com
// C:\Users\xx\.ssh\config
Host github.com
HostName ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443
测试
其实应该还有其他解决方案,当然关闭代理的全局模式是最快的。
6、设置远程地址
git remote origin set-url [url]
7、参考
ssh远程登陆有时候正常,有时候显示:ssh_exchange_identification: Connection closed by remote host,这是什么原因?