1. Switch to the private key and the public key storage directory
cd ~/.ssh
2. Generate a custom keys
ssh-keygen -t rsa -f ~/.ssh/id_rsa_xxx -C "邮箱地址"
View the generated public and private keys
yaomingyang:.ssh yaomingyang$ ls
config id_rsa.pub id_rsa_xxx.pub
id_rsa id_rsa_xxx known_hosts
id_rsa corresponding secret key is a secret key GitHub, id_rsa_xxx custom keys
3. Create a config file, and add the following configuration in the configuration file
# github
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa
# 公司账号
#别名
Host xx.xx.xx.xx
#主机名(IP地址或者域名)
HostName xx.xx.xx.xx
#端口
Port 45684
#秘钥
IdentityFile ~/.ssh/id_rsa_xxxx
By default, the host name and aliases are the same, you can also customize aliases, custom need to modify the project configuration
4. arranged to pull the public key code verification and the GitLab GitHub, Verify command can also ssh
yaomingyang:.ssh yaomingyang$ ssh -T [email protected]
Welcome to GitLab, yaomingyang!
5.Host alias and the host name is not the same HostName
Under need to switch to the project directory, open .git / config file
vi .git/config
core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = [email protected]:emis/api/com.xx.xx.utils.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
Xx.xx.xx.xx url modify the value of an alias, otherwise an error
6. Find the git path
yaomingyang:/ yaomingyang$ which git
/usr/bin/git