git 从远程git服务上拉代码 git服务器非默认端口

从服务器上拉代码有如下报错:

fatal: Not a git repository (or any of the parent directories): .git

初始代本地版本库:

[root@NB gitdb]# git init
Initialized empty Git repository in /data/gitdb/.git/

发生下面的报错:

git pull git@xx.xxx.xx.xx:yanjing_chenl/IT-DOC.git 
ssh: connect to host xx.xx.xx.xx port 22: Connection timed out
fatal: The remote end hung up unexpectedly

因为安全期间我改变了git服务器的端口为非22端口

ssh默认端口为22,而Git的访问是基于ssh的。为了安全我们会更改服务的ssh端口号,即当ssh的端口不是22端口时,git访问会出现:

ssh: connect to host xxx.com port 22: Connection timed out

无论客户端是在windows还是linux,配置访问的端口号,都是修改用户的.ssh文件里的config文件

以linux为例:用户root为例

/root/.ssh/config

config文件如果没有,则建一个

config中添加如下内容:

 #如果是以域名访问的则添加如下内容:
host xxx
HostName xxx.com
Port 3333
如果以ip访问的,则添加如下内容:
Host "12.123.xx.xx"
Port 3333
如我的机器是如下配置 
[root@NB ok]# cat ~/.ssh/config 
hostname x0.xx.xx.xx 
port xx0xx

问题解决

但还是有个很严重的问题,所有的ssh 加任何的ip都 会定向到 config文件里配的那个ip,也就是说所有的ssh都 会豋录到这个ip的服务器上!!!!

这个问题可以这样解决,只配置端口:

# cat ~/.ssh/config 
port 22022

 近期发现别一种:就是用http://xxx.xxx.xxx.xxx/yanjing_chenl/IT-DOC.git

原文地址:https://www.cnblogs.com/bass6/p/6382633.html