0%

github和gitlab使用密钥ssh连接

1. github

1.1 生成公钥私钥

1
ssh-keygen -t rsa -b 4096 -C "levonfly@gmail.com"

第一步sava file 写成 github,密码可以为空。

1.2 添加到github里面

1
2
3
cat github-unix2dos.pub

ssh-rsa ........ levonfly@gmail.com

添加到 https://github.com/settings/keys

注意:ssh-rsa 也要复制。

1.3 测试是否连接到github, 现在带上私钥

1
2
3
4
5
ssh -T git@github.com -i ~/.ssh/github-unix2dos 

// -i 后面是私钥
// Connection to ssh.github.com port 443 [tcp/https] succeeded!
// Hi unix2dos! You've successfully authenticated, but GitHub does not provide shell access.

1.4 添加到config, git使用私钥

1
2
3
4
5
6
Host github.com
HostName ssh.github.com
IdentityFile ~/.ssh/github-unix2dos
User unix2dos
Port 443
ProxyCommand nc -v -x 127.0.0.1:7890 %h %p

2. gitlab

2.1 添加到gitee里面

1
2
3
cat ~/.ssh/fhyx.pub

ssh-rsa .....== levonfly@gmail.com

2.2 测试是否连接, 现在带上私钥

1
2
 ssh -T git@git.work.work -i ~/.ssh/fhyx
Welcome to GitLab, @liuwei!

2.3 添加到config, git使用私钥

1
2
3
4
5
6
Host git.work.work
PubkeyAcceptedKeyTypes=+ssh-rsa
PubkeyAcceptedAlgorithms=+ssh-rsa
HostName git.work.work
IdentityFile ~/.ssh/fhyx
User liuwei
可以加首页作者微信,咨询相关问题!