GitHub项目突然ssh方式连接不上

雨中笑 SourceTree 经验 760热度

简介多个GitHub账号部署ssh的方法、公司的git和你自己项目的git冲突时的解决经验

昨天因为忘记了些Linux的命令行语句,就想着把之前记录在笔记里的Linux语句记录到文档里,弄完在Sourcetree(git管理工具)提交不成功。

然后我在命令行里,输入:

ssh -T git@github.com

提示超时了

ssh: connect to host github.com port 22: Connection timed out

回想了下,上次公司项目gitlab.orayer.com(公司项目的托管位置)配置更改了一些东西,可能影响到本地的github.com(个人项目的托管位置),那么重新配置下github.com的ssh就行了


1、设置Git的user name和email

git config --global user.name "雨中笑"
git config --global user.email "1171843306@qq.com "

2、生成 SSH 密钥

ssh-keygen -t rsa -C "1171843306@qq.com "

提示:

Enter file in which to save the key (/c/Users/.ssh/id_rsa):

输入id_rsa_my (.ssh下你自己要存放的位置)和公司项目的密钥不一样就行

提示:

Enter same passphrase again:

回车就行,git push那些就不需要密码了

这时.ssh下会生成两个文件:
id_rsa_my
id_rsa_my.pub

3、GitHub添加密钥

将上面生成的文件id_rsa_my.pub内容添加到github里

步骤:
登录github-> Settings-> SSH and GPG Keys-> New SSH key添加

4、.ssh下生成配置
生成config文件,内容:

# my
Host github.com
User 1171843306@qq.com
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_my
Port 443

5、验证

ssh -T git@github.com

提示下面内容就成功了

Hi 雨中笑! You've successfully authenticated, but GitHub does not provide shell access.


很赞哦!(3)

本文阅读量 1415发布于 2021年11月17日

您的访问IP 18.190.159.10最早于 2024年4月29日 10时21分56秒 阅读过本文 为本文提供了 1 热度 1 阅读量

文章评论
回帖