首页 > 代码库 > window下 配置gitlab ssh非端口22端口

window下 配置gitlab ssh非端口22端口

git config --global user.name "jack"git config --global user.email "jackluo@xxx.com"Create a new repositorymkdir fromai_cncd fromai_cngit inittouch README.mdgit add README.mdgit commit -m "first commit"git remote add origin git@git.xxx.cn:develper/xxx_cn.gitgit push -u origin masterPush an existing Git repositorycd existing_git_repogit remote add origin git@git.xxxx.cn:develper/xxx_cn.gitgit push -u origin master

这个是gitlab上面的配置 

window 下安装 git 的客户端,全是google的地址这里提供一个 http://pan.baidu.com/s/1i3ACfe1

安装好后,因为 服务器的端口ssh不是22号所以

先来配置 ssh自动登陆

ssh-keygen -t rsa -C jackluo@xxxx.com

修改方法,修改当前用户的home下的.ssh/config文件

vim ~/.ssh/confighost examplehostname example.comport 1234修改项目文件下的 .git/config 文件:[core]    repositoryformatversion = 0    filemode = false    bare = false    logallrefupdates = true    symlinks = false    ignorecase = true    hideDotFiles = dotGitOnly[remote "origin"]    url = git@example:develper/xxxx_cn.git    fetch = +refs/heads/*:refs/remotes/origin/*

最后把公钥添加到gitlab中

$ cat ~/.ssh/id_rsa.pubssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA1B0//oNYOKn6/SS2XyuMmCbys9bNlfuYvhLUYa9K989JuhSHhtnacCu+FdnL3XGQBrtFykjR+yHW3bNqqLa+oYJc12HOpTcgKLwWLROuy/5DLOaYatOxk0J4hk91zHINQKfcx0j/1aIFY9CZJWhdaUx48dhcIqSqskQrpaVC/uONliT5Xphr0HjdSI0wBLFPhTJrlzWOyA8FCvWDc93BydhJk3pwscFCaLH/69oi1BQQe+weweweXMsNv21+4kI5TDmDcgO5gagFyoq38TR2JM9khp1RO+5ekR/TW1qo9z1WJj6Phb9dazfL2wNaIGgfG1RNb0iNTQoGH+cOWBoL3/+jbQ== jackluo@xxxx.com
把这个复制 到 gitlab

My SSH keys 中

 

git push origin master

 ========================================================================

2. 生成ssh key时同时指定保存的文件名

ssh-keygen -t rsa -f ~/.ssh/id_rsa.sohu -C "email"

上面的id_rsa.sohu就是我们指定的文件名,这时~/.ssh目录下会多出id_rsa.sohuid_rsa.sohu.pub两个文件,id_rsa.sohu.pub里保存的就是我们要使用的key。

3. 新增并配置config文件

添加config文件

如果config文件不存在,先添加;存在则直接修改

touch ~/.ssh/config

config文件里添加如下内容(User表示你的用户名)

Host *.cloudscape.sohu.com    IdentityFile ~/.ssh/id_rsa.sohu    User test
==============================================================================================
#Default Git
Host defaultgit
  HostName IP Address #域名也可
  User think
  IdentityFile ~/.ssh/id_rsa
 
#Second Git
Host secondgit
  HostName IP Address #域名也可
  User think
  IdentityFile ~/.ssh/id_rsa_second
 

window下 配置gitlab ssh非端口22端口