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
相关推荐
AI蜗牛车8 分钟前
【LLM+Code】Github Copilot Agent/VsCode Agent 模式Prompt&Tools详细解读
人工智能·语言模型·github·copilot·agent
运营猫小海豚14 分钟前
DooTask功能与企业适配性分析
开源·github
油泼辣子多加1 小时前
2025年04月23日Github流行趋势
github
漫步企鹅1 小时前
[Git] Git Stash 命令详解
git·git push·git pull·git commit·git pull rebase
兮动人1 小时前
Idea使用github copilot登录bug+解决方案
github·bug·intellij-idea
船长@Quant3 小时前
协作开发攻略:Git全面使用指南 — 第二部分 高级技巧与最佳实践
git·版本控制·源代码管理·协作开发
梓羽玩Python3 小时前
告别OCR!这个AI文档神器直接"看懂"PDF,支持文档归类及多模态问答!
人工智能·github
uhakadotcom5 小时前
轻松理解vLLM:大语言模型推理的高效利器与实用示例
后端·面试·github
极小狐6 小时前
极狐GitLab Git LFS 速率限制如何设置?
运维·git·ssh·gitlab·github