Roly's Blog

Whatever will be, will be, the future's not ours to see.

0%

Mac下配置多个SSH-Key

生成SSH-Key

打开终端,前往.ssh目录

配置多个SSH-Key1

生成一个SSH-Key

1
$ ssh-keygen -t rsa -C "youremail@email.com"

自定义生成key的名字

配置多个SSH-Key2

设置密码

配置多个SSH-Key3

修改RSA私钥上的密码

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

成功生成SSH-Key

配置多个SSH-Key4

配置SSH-Key

在~/.ssh/目录下会生成id-rsa_hostname和id-rsa_hostname.pub私钥和公钥。 我们将id-rsa_hostname.pub中的内容粘帖到服务器的SSH-key的配置中。

1
$ cat id_rsa_hostname.pub

Mac下配置多个SSH-Key5

在GitHub的设置中粘贴公钥

Mac下配置多个SSH-Key6

测试

1
$ ssh -T git@github.com

Mac下配置多个SSH-Key8

配置多个SSH-Key

打开Finder前往.ssh文件夹

Mac下配置多个SSH-Key7

Mac下配置多个SSH-Key8

编辑config文件

Mac下配置多个SSH-Key8

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github //github对应的私钥

# coding.net
Host git.coding.net
User youremail.com //coding对应的email
PreferredAuthentications publickey
IdentityFile ~/.ssh/blog //coding对应的私钥

# coding.net
Host git.coding.net
User youremail.com //coding对应的email
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa //coding对应的私钥