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
修改项目文件下的 .git/config 文件:
[core]
repositoryformatversion =
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
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 *