Linux如何通过脚本实现远程自动备份
为了避免数据丢掉咱们常常做的就是在电脑上备份这些数据,不过虽然备份了数据比拟安全,可是若是数据地点的电脑发作问题怎么办呢,考虑到在本机上备份数据,一旦该机器硬盘呈现毛病,数据无法取出。长途手动备份数据费时吃力且不及时。最棒的方法就是经过脚本完成长途主动互备。但长途无论是经过SSH登入,仍是经过scp复制文件都需求输入暗码。为了战胜这个问题,首要需求完成不需求暗码的SSH登入,这样就可以运用rsync,scp,rexec等指令来做的长途备份了。
1. 设置无需暗码的ssh登入,方法如下:
假定A,B两服务器,如今需求在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): /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:
f6:61:a8:27:35:cf:4c:6d:13:22:70:cf:4c:c8:a0:23 root@host1
这样,在/root/.ssh/途径下会生成id_rsa,和id_rsa.pub,其间id_rsa是密钥,id_rsa.pub是公钥。