Error handling when using Git

1. ssh: connect to host github.com port 22: Bad file number
解决这个问题,用Https来完全避免SSH。大多数防火墙和代理允许使用HTTPS,所以改写远程URL:

由SSH改到HTTPS: git clone https://github.com/username/reponame.git

有时候要使用SSH而非HTTPS。防火墙有时候完全禁止SSH访问。尝试SSH是否好用:

ssh -T -p 443 git@ssh.github.com

如果好用则返回:

Hi username! You’ve successfully authenticated, but GitHub does not provide shell access.

如果出问题了,可能是端口问题。测试端口是否打开:

  • 方法1:

这里写图片描述

或者:

nmap -sS github.com -p 443

图片显示端口443被过滤掉了。有关端口的各个状态的意思可以在这里查到。

解决方法:
在.ssh文件中创建一个config文件,内容如下:

Host github.com
User git
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

保存文件,在bash中输入:

ssh -T github.com

之后,会让你输入passphrase。
一开始这个方法行不通,输入之后还是从22端口访问,我只知道我的ssh需要设置代理。所以,我下载了proxifier来设置全局代理。设置成功后,再运行,结果如下,可以看到还是有问题“ssh_exchange_identification: Connection closed by remote host”,这个问题网上的描述很复杂,有很多个因素导致这个问题,我就放弃用command命令行来搞Github了,还是用GUI好了。。

这里写图片描述

后来跑步的时候突然想起来可能是config文件扩展名的问题。回来一查,真是!我保存的时候忽略了会自动加载扩展名.txt,把扩展名删掉之后成功。结果如下:

这里写图片描述

2. The agent has no identities

cd ~/.ssh
eval $(ssh-agent)
ssh-add
ssh-add -L

这里要用Git Bash。直接用windows的命令行是不行的。各种系统的解决方法可以在这里找到。

3. fatal: Not a git repository (or any of the parent directories): .git
必须要在你想创建git repository的文件夹里面init:

git init

4. Change proxy

git config –global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
git config –global https.proxy https://proxyuser:proxypwd@proxy.server.com:8080

proxyuser: proxy user
proxypwd: proxy password
proxy.server.com: URL of your proxy server
8080: proxy port ocnfigured on your proxy server

如果想关掉全局Proxy:

git config –global –unset http.proxy
git config –global –unset https.proxy

5. ssh_exchange_identification: Connection closed by remote host

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值