linux远程备份文件

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

linxu远程备份文件

1设置无需密码的ssh登陆方法如下
假设AB两服务器现在需要在A主服务器机上用root登陆B备份服务器机而不需要输入密码那我们可按照下面的步骤来做
1在A主服务器机上生成钥匙对,执行以下命令

ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 直接回车
Enter passphrase (empty for no passphrase): 直接回车
Enter same passphrase again: 直接回车
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
11:3f:01:84:12:94💿f2:6a:0b:73:35:e9:41:09:6d root@admin

这样在/root/.ssh/路径下会生成id_rsa和id_rsa.pub其中id_rsa是密钥id_rsa.pub是公钥。

2把在A主服务器机生成的id_rsa.pub拷贝到B备份服务器机上假设拷贝到B机的临时目录下如

scp -P 22 /root/.ssh/id_rsa.pub root@172.16.3.250:/tmp

3用root帐号登陆B备份服务器机进入其主目录创建authorized_keys文件并设置好权限。

cd ~/.ssh
cat /tmp/id_rsa.pub >>authorized_keys
chmod 400 authorized_keys
rm -f /tmp/id_rsa.pub

4测试
在A主服务器机上转到root帐号尝试登录B备份服务器机。看看是不是不要密码.

scp -P 22 /home/1.txt root@172.16.3.250:/home

说明
authorized_keys文件的权限很重要如果设置为777那么登录的时候还是需要提供密码的。
记得将临时目录下的id_rsa.pub删除

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: linux