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被过滤掉了。有关端口的各个状态的意思可以在这里查到。
- 方法2:
在IE中输入,https://www.microsoft.com: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