git config --global user.name "jack" git config --global user.email "jackluo@xxx.com" Create a new repository mkdir fromai_cn cd fromai_cn git init touch README.md git add README.md git commit -m "first commit" git remote add origin git@git.xxx.cn:develper/xxx_cn.git git push -u origin master Push an existing Git repository cd existing_git_repo git remote add origin git@git.xxxx.cn:develper/xxx_cn.git git 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/config host example hostname example.com port 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.pub ssh-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.sohu和id_rsa.sohu.pub兩個文件,id_rsa.sohu.pub里保存的就是我們要使用的key。
HOST fromai hostname xxxxx IdentityFile /home/jackluo/.ssh/id_rsa.fromai port 2222
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
=========================================================
Bad owner or permissions on $HOME/.ssh/config
The ssh with RHEL 4 is a lot more anal about security checking. In my case, it was the fact that $HOME/.ssh/config was group-writable which was causing it to barf. To fix:
$ cd ~/.ssh $ chmod 600 *
