github 和 gitee 配置问题及相关问题解决

一、电脑基础配置

bash 复制代码
git config --global user.name 用户名【任意名字均可,可以和账户名称一致】
git config --global user.email【账号的邮箱地址】

二、生成各自账号的 SSH 在C:\\Users\\【自己电脑的用户名】/.ssh文件夹中,ctrl右键打开 git bash 控制窗口,然后输入以下命令一直回车... 即可。

bash 复制代码
ssh-keygen -t rsa -f id_rsa.gitee -C "gitee"
ssh-keygen -t rsa -f id_rsa.github -C "github"

最终结果如下:

三、配置生成一个config文件,用记事本打开,输入以下内容

txt 复制代码
# gitHub
Host github.com
HostName ssh.github.com
User 【账号的邮箱地址】
Port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa.github

# gitee
Host gitee.com
HostName gitee.com
IdentityFile ~/.ssh/id_rsa.gitee
PreferredAuthentications publickey

四、将对应的SSH配置到对应的站点

略。

五、测试连接

bash 复制代码
ssh -T [email protected] # 测试Gitee
ssh -T [email protected] # 测试GitHub

【或者输入yes后】提示你Hi 用户名! You've successfully authenticated, but GitHub does not provide shell access. 那么旧恭喜你万事大吉。

六、测试连接GitHub可能出现的问题:

bash 复制代码
PS C:\Users\52803> ssh -vT [email protected]
OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2
debug1: Reading configuration data C:\\Users\\52803/.ssh/config
debug1: C:\\Users\\52803/.ssh/config line 8: Applying options for github.com
debug1: Connecting to ssh.github.com [127.0.0.1] port 443.
debug1: connect to address 127.0.0.1 port 443: Connection refused
ssh: connect to host ssh.github.com port 443: Connection refused

这个问题我遇到的大部分修改端口号,我之前本来就是选择了443,然后就是代理设置也不生效,重新安装git也不生效,重新生成ssh也不管用,设置GitHub的域名地址IP也不对。。。。。 最后发现是要生成 ssh.github.com 的域名IP地址。

在文件夹C:\Windows\System32\drivers\etc下,修改 hosts 文件

配置如下:

复制代码
140.82.113.36          ssh.github.com
140.82.114.35          ssh.github.com

配置后ipconfig /flushdns刷新。然后再测试连接。

提供查询的网站

希望大家配置顺利,不会有这些奇怪的问题。参考文档

其他问题: 比如:重新生成了ssh,之前ssh依赖的工程,再push、pull会报错,我的解决方式就是:

bash 复制代码
git remote rm origin
git remote add origin 仓库名称
git push -u origin master
相关推荐
小慧10246 分钟前
1.2 git使用
git
m0_635647484 小时前
git管理github上的repository(二)
git·github
qianmoQ6 小时前
GitHub 趋势日报 (2025年06月08日)
github
Aisanyi9 小时前
【鸿蒙开发从入门到放弃】新建项目,并接入Git
github·harmonyos
今夕节度使11 小时前
通过 VS Code 连接 GitLab 并上传项目
git·elasticsearch·gitlab
陈 洪 伟11 小时前
复习Git命令、Git命令使用流程、VSCode+Git插件管理工程源码
git
百锦再13 小时前
Git 使用大全:从入门到精通
git·version·版本·代码·分支·code·clone
阿群的AI工作室13 小时前
新手必看喂饭级教程🔥原来这样用SSH推代码到GitHub才对!
github
中微子14 小时前
📝 终极Git Commit Message规范指南:写出专业级提交记录
git·github