github多个ssh key应用

    以mac下多个不同ssh key提交到不同github上为例:

1.安装 ssh

Apple$ ssh -v
usage: ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-E log_file] [-e escape_char]
           [-F configfile] [-I pkcs11] [-i identity_file]
           [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec]
           [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]
           [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]
           [user@]hostname [command]

mac下已经默认安装好了ssh

2.生成两个不同账号的ssh key

ssh-keygen -t rsa -C "test1@email.com" // 一路enter即可...

ssh-keygen -t rsa -C "test2@email.com" // 同上

进入.ssh目录

:.ssh Apple$ ls
authorized_keys	id_rsa		known_hosts	user2.pub
config		id_rsa.pub	user2

ssh默认只读取id_rsa,为了让SSH识别新的私钥,需将其添加到SSH agent中:

ssh-add ~/.ssh/user2

如果出现Could not open a connection to your authentication agent的错误,就试着用以下命令:

ssh-agent bash

ssh-add ~/.ssh/user2

接下来配置一下config文件,如果没有就创建一个

.ssh Apple$ touch config

:.ssh Apple$ cat config 
Host github.com
	HostName github.com
	PreferredAuthentications publickey   
        IdentityFile ~/.ssh/id_rsa
 
 
Host frankwii.com
      	HostName github.com 
	PreferredAuthentications publickey   
	IdentityFile ~/.ssh/user2

这个时候注意一下,如果你的github上的仓库添加的是sshkey是user2.pub那么地址应该为

git@frankwii.com:frankwii/meiqi.git

至于你要访问github项目将你的.pub文件扔到要访问的github中即可

174616_EBnL_3463135.png

密钥添加完成后,你还可以测试一下:

ssh -T git@frankwii.com
Hi wii95! You've successfully authenticated, but GitHub does not provide shell access.

 

转载于:https://my.oschina.net/wii01/blog/893924

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值