Linux下如何管理多个git ssh密钥

问题:

今天在github上建立了账号,因为自己邮箱的改动,所以我在Linux下重新对git进行全局配置,用以为github生成新的私钥与公钥,但是我的/.ssh/文件夹下有以前为码云创建的密钥,故我把以前的私钥与公钥更名,然后发现不能连接到码云

解决过程:

[wt@localhost ~] $ git config --global user.name "wangtao"                     //  Linux上

[wt@localhost ~] $ git config --global user.email "TAlicer@163.com //对git进行全局配置

[wt@localhost ~] $  ssh-keygen -t rsa -C "TAlice@163.com"

Generating public/private rsa key pair.

Enter file in which to save the key (/home/guowenxue/.ssh/id_rsa): 按回车

/home/guowenxue/.ssh/id_rsa already exists.

Overwrite (y/n)? y

Enter passphrase (empty for no passphrase): 按回车

Enter same passphrase again: 按回车

Your identification has been saved in /home/wt/.ssh/id_rsa  私钥

Your public key has been saved in /home/wt/.ssh/id_rsa.pub  公钥

但是我的/.ssh/文件夹下有以前为码云创建的密钥,故我把以前的私钥与公钥重命名为id_rsa1,id_rsa1.pub

即为:

[wt@localhost .ssh]$ ls

id_rsa  id_rsa1  id_rsa1.pub  id_rsa.pub

然后我做码云连接测试一直出现错误

[wt@localhost ~] $ ssh -T git@git.oschina.net

Permission denied (publickey).

解决办法是在/.ssh/下新建一个config文件(无文件后缀名!!!),内容为

Host就是你的git仓库的域名或者IP,例如:github、码云的域名~ 
IdentityFile指定你连接git仓库的私有密钥文件路径,前提是把密钥名改为相应的名字

然后我们再做码云连接测试

[wangtao@centos6 ~]$ ssh -T git@git.oschina.net

Welcome to Gitee.com, TAlice!

ok!

另外,从github上克隆项目的时候出现

Warning: Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts.

可以修改hosts文件消除警告,添加192.30.252.128  github.com

[wt@localhost ~]$ sudo vim /etc/hosts

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值