您的位置:首页 > 其它

在同一台电脑上添加多个ssh key

2017-03-18 10:11 141 查看
1.创建新的ssh key:

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; text-align: justify; font: 16.0px "PingFang SC"; color: #333333 }
span.s1 { }
ssh-keygen -t rsa -C "your_email@email.com"

然后让你输入新的文件名称,这里设置为new

# 设置名称为Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): ~/.ssh/new

2.密钥添加到SSH agent中

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; text-align: justify; font: 16.0px "PingFang SC"; color: #333333 }
span.s1 { }
ssh-add ~/.ssh/new

ssh-add -l 可以查看添加过的密钥

shh-add -D 可以删除

如果出现Could not open a connection to your authentication agen

就执行:

ssh-agent bash

ssh-add ~/.ssh/new

3.把创建的~/.ssh/new.pub中的内容添加到你的github账号上。

4.在~/.ssh创建或者修改config文件

# new
Host new
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/new

5.测试

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; text-align: justify; font: 16.0px "PingFang SC"; color: #333333 }
span.s1 { }
ssh -T git@new

6.clone仓库

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; text-align: justify; font: 16.0px "PingFang SC"; color: #333333 }
span.s1 { }
git clone git@new:username/git-demo.git

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; text-align: justify; font: 16.0px "PingFang SC"; color: #333333 }
span.s1 { }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; text-align: justify; font: 16.0px "PingFang SC"; color: #333333 }
span.s1 { }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: