检查已经存在的ssh keys

1
ls -al ~/.ssh

新建ssh key

1
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

使用ssh-agent来管理ssh key

1
2
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa

修改ssh key的密码

1
ssh-keygen -f ~/.ssh/id_rsa -p

配置不同的host使用不同的ssh

~/.ssh文件夹下,新建config文件并写入下面的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Host xxx.com
HostName 192.168.1.1
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/sampwood_id_rsa
IdentitiesOnly yes
Host gitlab.com
HostName gitlab.com
User git
IdentityFile ~/.ssh/sampwood_id_rsa
IdentitiesOnly yes

参考

  1. Connecting to GitHub with SSH