生成ssh key及配置多个ssh key

来源:互联网 发布:桐乡淘宝美工 编辑:程序博客网 时间:2024/05/16 14:10

公司有个git服务,自己写的代码也放在oschina上,那怎么才能配置两个ssh key呢,保证两个服务同时可用,下面就说下怎么配置多个ssh key。

电脑上原先已经有一个ssh key了,是公司的,就不在说怎么生成了,现在说下怎么再生成一个key且不覆盖旧的。

bogon:.ssh my$ ssh-keygen -t rsa -C "xxxx@xxx.com"Generating public/private rsa key pair.Enter file in which to save the key (/Users/my/.ssh/id_rsa): id_rsa_oschina//在这里写新的文件名id_rsa_oschina already exists.Overwrite (y/n)? yEnter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in id_rsa_oschina.Your public key has been saved in id_rsa_oschina.pub.The key fingerprint is:SHA256:fYx/nP9Nxxxxxxxdd/6cKReriyoAxxxxxxxP1p54V4c xxxx@xxx.comThe key's randomart image is://省略bogon:.ssh my$

注意一定要写文件名啊,要不就把旧的覆盖掉了。

现在试试是否可以连接oschina了

bogon:.ssh my$ ssh -T git@git.oschina.netPermission denied (publickey).

说明不可以,下面做个配置,让两个key都可以用。

bogon:.ssh my$ cd ~/.ssh/bogon:.ssh my$ vim config//以下是文件内容# Default github user(company@xxx.com)  Host git.company.com  HostName git.company.com  User my  IdentityFile /Users/my/.ssh/id_rsa# second user(xxxx@xxx.com)  Host git.oschina.net  HostName git.oschina.net  User my  IdentityFile /Users/my/.ssh/id_rsa_oschina//保存文件

下面测试下是否可以连接oschina

bogon:.ssh my$ ssh -T git@git.company.comWelcome to GitLab, my!bogon:.ssh my$ ssh -T git@git.oschina.netWelcome to Git@OSC, my!

OK,两个git服务都可用了,其实最主要的就是~/.ssh/config文件,配置好这个就大功告成。

0 0
原创粉丝点击