问题:
今天在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