一,服务器A
1, 首先用服务器A产生公钥与私钥
[wt@localhost ~] $ git config --global user.name "wangtao" // Linux上
[wt@localhost ~] $ git config --global user.email "764234****@qq.com" //对git进行全局配置
[wt@localhost ~] $ ssh-keygen -t rsa -C "764234****@qq.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 公钥
The key fingerprint is:
10:54:26:ff:39:87:fe:a7:df:d8:b8:b1:15:6c:63:86 764234****@qq.com
The key's randomart image is:
+--[ RSA 2048]----+
| .+.o |
| = |
| . . |
| . . o o |
| S = .E B |
| . o + o|
| . . .|
| . .O |
| o+*.o|
+-----------------+
2,查看public key并拷贝,将它添加到码云个人帐号的SSH公钥里:
[wt@localhost ~] $ cat ~/.ssh/id_rsa.pub
ssh-rsa ******** == "764234****@qq.com" //公钥
3,公钥添加测试:
[wt@localhost ~] $ ssh -T git@git.oschina.net
The authenticity of host 'git.oschina.net (120.55.226.24)' can't be established.
RSA key fingerprint is e3:ee:82:78:fb:c0:ca:24:65:69:ba:bc:47:24:6f:d4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'git.oschina.net' (RSA) to the list of known hosts.
Welcome to Gitee.com, TAlice!
二,服务器B
1,现在我们用服务器B登录码云
[wangtao@centos6 ~]$ mkdir .ssh //创建.ssh文件夹
..... //将之前服务器上产生的公钥与私钥文件复制到该服务器的.ssh文件夹下
[wangtao@centos6 .ssh]$ ls
id_rsa id_rsa.pub
2, 公钥添加测试:
[wangtao@centos6 .ssh]$ ssh -T git@git.oschina.net
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/home/wangtao/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: /home/wangtao/.ssh/id_rsa
Permission denied (publickey).
我们发现并不能登录到码云,这是因为复制过来后的私钥权限变为了0644,系统认为私钥的权限太过开放
[wangtao@centos6 .ssh]$ chmod 0600 id_rsa //我们将私钥的权限改为0600
[wangtao@centos6 .ssh]$ ssh -T git@git.oschina.net
Welcome to Gitee.com, TAlice!
OK! 现在我们成功登录到码云!