同一台电脑,github、阿里云code git ssh key 登录
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): /c/Users/Administrator/.ssh/id_rsa_user2
问题:如果是多用户如user1,user2,在同一台服务器上,那么id_rsa_pub就不能用在user2的身上了,怎么办呢?
一、新建user1、user2的SSH Key
#新建user1 SSH key:
$ cd ~/.ssh ssh-keygen -t rsa -C "user1@email.com"
一路回车即可;
# 新建user2的SSH key
#ssh-keygen -t rsa -C "user2@email.com"
# 设置名称为
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): /c/Users/Administrator/.ssh/id_rsa_al
id_rsa_al,这里起了一个新的文件名,ssh目录下已经有默认的id_rsa文件。
二、密钥添加到SSH agent中
因为默认只读取id_rsa,为了让SSH识别新的私钥,需将其添加到SSH agent中:
ssh-add ~/.ssh/id_rsa_al
如果出现Could not open a connection to your authentication agent的错误,就试着用以下命令:
ssh-agent bash ssh-add ~/.ssh/id_rsa_user2
三、修改config文件
在~/.ssh目录下找到config文件,如果没有就创建:
touch config
然后修改我的config配置如下:
Host code.aliyun.com HostName code.aliyun.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa_al Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa
其规则就是:从上至下读取config的内容,在每个Host下寻找对应的私钥。
四、
打开新生成的~/.ssh/id_rsa_al.pub文件,将里面的内容添加到GitHub后台。(第二个新账号)
第一个github帐号下的SSH Key中也要记得添加。(添加到第一个账号)
浙公网安备 33010602011771号