1 设置gitlab sshkey
(1) config gitlab name & email
git config --global user.name "your gitlab uname"
git config --global user.email "your gitlab email"
(2) key gen 一路 default 即可
ssh-keygen -t rsa -C "GitLib" -b 4096
(3) 登录gitlab添加sshkey
2 设置github sshkey(需要设置不同的sshkey文件名)
(1) config github name & email
git config --global user.name "your github uname"
git config --global user.email "your github email"
(2) key gen
$ ssh-keygen -t rsa -C "your github email"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/user/your name/.ssh/id_rsa):github_id_rsa
(3) 登录github添加sshkey
3 github&gitlab共存
(1) ssh-add
ssh-add ~/.ssh/your sshkey name
若出现Could not open a connection to your authentication agent,尝试以下命令
ssh-agent bash
ssh-add ~/.ssh/hty
(2) touch config
cd ~\.ssh
touch config
config内容如下
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa
Host gitlab
HostName code.xxxx.com.cn
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
(3) 验证
ssh -T git@github.com
ssh -T git@gitlab
[TIP]如果仍验证失败,试一下git config --global name&email 换成对应的账号
网友评论