两台vps使用rsync+ssh同步文件设置免密钥的操作记录
两台vps,分别为
1.nihaoa.xyz
2.nihaoa.xyz
登陆1.nihaoa.xyz
敲命令行
ssh-keygen -t rsa
返回
Generating public/private rsa key pair. [生成公共/私有rsa密钥对。]
Enter file in which to save the key (/root/.ssh/id_rsa): [输入保存密钥的文件(/root/.ssh/id_rsa):]
敲回车保存
/root/.ssh/id_rsa already exists. [/根/。ssh/id_rsa已经存在。]
Overwrite (y/n)? [是否覆盖(是/否)?]
敲命令
y
返回
Enter passphrase (empty for no passphrase): [输入密码短语(无密码短语为空):]
此例密码设置为空,敲回车 (如果设置不为空密码,则输入想要的密码)
返回
Enter same passphrase again: [再次输入相同的密码短语:]
再次输入密码为空,敲回车
返回
Your identification has been saved in /root/.ssh/id_rsa. [您的身份已保存在/root/中。ssh/id_rsa。]
Your public key has been saved in /root/.ssh/id_rsa.pub. [您的公钥已保存在/root/中。ssh/id_rsa.pub]
The key fingerprint is: [关键指纹是:]
A1:b2:C3:d4:E5:f6:G7:h8:I9:j0:K1:l2:M3:n4:O5:p6 root@1.nihaoa.xyz [左边的就是指纹,右边的是vps名字]
The key's randomart image is: [钥匙的随机艺术形象是:钥匙内容是处理过的]
+--[ RSA 2048]----+
| |
| |
| 1 |
| 2 3 |
| 45 |
| 6 7 8 |
| 910=2 |
| 1.NiHaoA. |
| xyz. |
+-----------------+
root@1.nihaoa.xyz:~#
敲查看命令
ls ~/.ssh/
返回目录下的密钥文件
authorized_keys id_rsa id_rsa.pub known_hosts
将公钥id_rsa.pub复制到被管理机器2.nihaoa.xyz上面
敲命令进入~/.ssh/目录,
cd ~/.ssh/
root@1.nihaoa.xyz:~/.ssh#
敲命令复制密钥id_rsa.pub到2.nihaoa.xyz:~/.ssh/目录下
scp id_rsa.pub root@2.nihaoa.xyz:~/.ssh/authorized_keys
返回,
id_rsa.pub 100% 390 0.4KB/s 00:00
敲命令退到根目录
cd
root@1.nihaoa.xyz:~#
敲命令登陆到2.nihaoa.xyz
ssh 2.nihaoa.xyz
返回
能直接进到2.nihaoa.xyz这台vps了,
返回显示
root@2.nihaoa.xyz:~#
以上1.nihaoa.xyz vps设置完成。
——————————————————————
在 2.nihaoa.xyz 另一台vps也设置免密钥来同步文件。
登陆进到2.nihaoa.xyz
root@2.nihaoa.xyz:~#
敲命令行
ssh-keygen -t rsa
返回
Generating public/private rsa key pair. [生成公共/私有rsa密钥对。]
Enter file in which to save the key (/root/.ssh/id_rsa): [输入保存密钥的文件(/root/.ssh/id_rsa):]
敲回车保存
Enter passphrase (empty for no passphrase): [输入密码短语(无密码短语为空):]
此例密码设置为空,敲回车 (如果设置不为空密码,则输入想要的密码)
Enter same passphrase again: [再次输入相同的密码短语:]
再次输入密码为空,敲回车
返回
Your identification has been saved in /root/.ssh/id_rsa. [您的身份已保存在/root/中。ssh/id_rsa。]
Your public key has been saved in /root/.ssh/id_rsa.pub. [您的公钥已保存在/root/中。ssh/id_rsa.pub]
The key fingerprint is: [关键指纹是:]
A1:b2:C3:d4:E5:f6:G7:h8:I9:j0:K1:l2:M3:n4:O5:p6 root@2.nihaoa.xyz [左边的就是指纹,右边的是vps名字]
The key's randomart image is: [钥匙的随机艺术形象是:钥匙内容是处理过的]
+--[ RSA 2048]----+
| |
| |
| 1 |
| 2 3 |
| 45 |
| 6 7 8 |
| 910=2 |
| 2.NiHaoA. |
| xyz. |
+-----------------+
root@2.nihaoa.xyz:~#
敲查看命令ssh下的密钥文件
ls ~/.ssh/
返回以下
authorized_keys id_rsa id_rsa.pub known_hosts
将公钥id_rsa.pub 复制到被管理机器1.nihaoa.xyz上面
敲命令进入~/.ssh/目录
cd ~/.ssh/
返回
root@2.nihaoa.xyz:~/.ssh#
敲命令复制密钥id_rsa.pub到1.nihaoa.xyz:~/.ssh/目录下
scp id_rsa.pub root@1.nihaoa.xyz:~/.ssh/authorized_keys
提示root@1.nihaoa.xyz's password: [提示输入密码]
输入密码
返回
id_rsa.pub 100% 391 0.4KB/s 00:00
敲命令退到根目录
cd
root@2.nihaoa.xyz:~#
敲命令登陆到1.nihaoa.xyz
ssh 1.nihaoa.xyz
能直接进到 1.nihaoa.xyz 这一台vps了
返回显示
root@1.nihaoa.xyz:~#
以上2.nihaoa.xyz vps设置完成。
两台vps,1.nihaoa.xyz,2.nihaoa.xyz可以实现免密钥同步文件。
(以上为操作记录,看起来比较复杂,但是跟着步骤来操作就不难了。)