多个GitHub账号配置ssh key

生成并添加第一个ssh key

$ ssh-keygen -t rsa -C "[email protected]"

在Git Bash中执行命令一路回车,会在~/.ssh/目录下生成id_rsa和id_rsa.pub两个文件
用文本编辑器打开id_rsa.pub,在Github中添加SSH Keys。

生成并添加第二个ssh key

$ ssh-keygen -t rsa -C "[email protected]"

这次不能一路回车,给这个文件起一个名字 不然默认的话就覆盖了之前生成的第一个。

图示

目录结构

id_ras
id_ras.pub
my
my.pub

如果生成的第二个 ssh key 不在~/.ssh/目录下,可以移动到此目录。

在~/.ssh/下创建config文件

Host github.com  
    HostName github.com  
    PreferredAuthentications publickey  
    IdentityFile ~/.ssh/id_rsa  
  
Host my.github.com  
    HostName github.com  
    PreferredAuthentications publickey  
    IdentityFile ~/.ssh/my  

测试正确性

ssh -T [email protected]
ssh -T [email protected]

如果出现Hi xxx!You've successfully authenticated 就说明连接成功了

你可能感兴趣的:(多个GitHub账号配置ssh key)