创建.ssh文件

所有操作均在~/.ssh/路径中进行

1
2
#如果不存在就创建.ssh文件
mkdir ~/.ssh

生成密钥对

1
2
3
4
5
6
#github
ssh-keygen -t rsa -C "your email address" -f "id_rsa_github"
#coding
ssh-keygen -t rsa -C "your email address" -f "id_rsa_github"
#gitlab
ssh-keygen -t rsa -C "your email address" -f "id_rsa_gitlab"

注:此部分全程回车即可

Generating public/private rsa key pair.

Enter passphrase (empty for no passphrase):

添加SSH公钥

github添加SSH公钥

使用cat命令查看公钥内容,复制公匙粘贴至https://github.com/settings/keys,然后选择New SSH key, title可不填写,将复制的公匙粘贴到key中再点击Add SSH key

cat id_rsa_github.pub


gitlab添加SSH公钥

使用cat命令查看公钥内容,复制公匙粘贴至https://gitlab.com/-/profile/keys,将公匙粘贴到key中再点击Add key,Title自动生成,也可自行修改

cat id_rsa_gitlab.pub

coding添加SSH公钥

参考此文