git问题
2023.5.20 git上传问题
第一种问题
$ git pull
ssh: connect to host github.com port 22: Connection refused
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
原因
ssh: connect: to host github.com port 22: Connection refused这个错误提示的是连接github.com的22端口被拒绝了。22端口可能被防火墙屏蔽了,可以尝试连接GitHub的443端口。
解决:
- 执行命令ssh -T -p 443 [email protected] 后不再提示connection refused
- 给~/.ssh/config文件里添加如下内容,这样ssh连接GitHub的时候就会使用443端口。
Host github.com
Hostname ssh.github.com
Port 443
- 如果~/.ssh目录下没有config文件,新建一个即可。
修改完~/.ssh/config文件后,使用ssh -T [email protected]来测试和GitHub的网络通信是否正常,如果提示.Hi xxxxx! You’ve successfully authenticated, but GitHub does not provide shell access. 就表示一切正常了。
但是,这个方案在我这里行不通,修改后还是提示ssh: connect to host github.com port 443: Connection refused。
这个方案有效的前提是:执行命令ssh -T -p 443 [email protected]后不再提示connection refused,所以要尝试这个方案的小伙伴先执行这条命令测试下。
第二种问题
Please make sure you have the correct access rights
and the repository exists.
FATAL Something’s wrong. Maybe you can find the solution here: https://hexo.io/docs/
troubleshooting.html
原因:
公钥出问题了,需要删除.ssh下文件,然后重设置用户名和邮箱再重新生成ssh公钥即可解决
解决:
- 删除.ssh下所有所有文件(C:\Users[“你的用户名”].ssh)
- 重新配置用户名
1
2
3
4
5
6 1.设置用户名
git config --global user.name "github用户名"
2.设置用户名邮箱
git config --global user.email ‘github注册邮箱’
3.查看设置
git config --list
- 生成公钥
1
2 #一直按回车就行,大概4下
ssh-keygen -t rsa -C "你刚刚绑定的邮箱"
- 绑定github
- 头像->settings->SSH and GPG Keys
- new SSH Keys
- 标题随便填,
- Authentication Key
- 把刚刚生成的id_rsa.pub里的内容粘贴到key栏里面
ssh连接问题
1 | ssh:connect to host github.com port 22: Connection timed out |
解决办法:
方法一:抛弃ssh连接方式,使用http连接。(我没有用)
1.在仓库文件夹内,查看隐藏文件.git
2.进入.git,找到config,用记事本打开
3.将 url = [email protected]:username/repo.git改成 url = https://github.com/username/repo.git (这里的地址改成你自己的地址)
方法二:如果22号端口不行,那就换一个端口
1.进入ssh秘钥存放文件夹(C:\Users[你的用户名].ssh)
2.新建记事本文件,命名为config,并删除后缀名
3.写入一下内容,保存退出
1 | Host github.com |
4.测试是否成功
1 | ssh -T [email protected] |
tips:这里要根据它的提示操作,有个地方要输入yes