Fork me on GitHub

Linux之服务器修改SSH默认端口后git访问设置

Linux之服务器修改SSH默认端口后git访问设置

前言

由于安全或者其它原因,可能会修改默认的SSH服务端口号,默认情况下,已有的git项目在pull或者push的时候会报错。
假设原来的项目的remote设置为[email protected]:mds1455975151/tools.git,将服务器SSH默认端口修改为4000后,导致pull或push出错。
报错信息如下:

1
2
3
4
5
6
# git pull
ssh: connect to host github.com port 4000: Connection timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

实践记录

解决方案1:直接修改URL为SSH://开头

1
2
3
4
5
# git remote -v
origin [email protected]:mds1455975151/tools.git (fetch)
origin [email protected]:mds1455975151/tools.git (push)
# git remote set-url origin ssh://[email protected]:22/mds1455975151/tools.git
# git pull

由于修改了访问方式需要添加github的deploy key

解决方案2:修改本地配置文件

1
2
3
4
5
6
7
8
9
10
11
# cat >>~/.ssh/config<<EOF

host proxy.github.com
Hostname github.com
Port 22
EOF
# git remote -v
origin [email protected]:mds1455975151/tools.git (fetch)
origin [email protected]:mds1455975151/tools.git (push)
# git remote set-url origin [email protected]:mds1455975151/tools.git
# git pull

参考资料

https://blog.csdn.net/yuliying/article/details/68956765

======================================================
希望各位朋友支持一下

本文作者:dongsheng
本文地址https://mds1455975151.github.io/archives/bdb4d807.html
版权声明:转载请注明出处!

坚持技术分享,您的支持将鼓励我继续创作!