Remote automatic backup via script under Linux

Source: Internet
Author: User
Tags ssh file permissions backup

Given that the data is backed up on this computer, the data cannot be removed once the machine's hard drive fails. Remote manual backup data is time-consuming, laborious, and timely. The best way to do this is by scripting Remote automated provisioning. However, a password is required for remote access either via SSH or through the SCP copy file. To overcome this problem, you first need to implement SSH login without a password, so you can use the RSYNC,SCP, rexec and other commands to do remote backup.

1. Set SSH login without password, as follows:

Assuming a, b two servers, now need to log on a machine with Root B machine, and do not need to enter a password, then we can follow the following steps to do:

1 to generate the key pair on a machine, execute the following command:

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): direct return

Enter same passphrase again: direct return

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

In this way, Id_rsa, and id_rsa.pub are generated under the/root/.ssh/path, where Id_rsa is the key and the id_rsa.pub is the public key.

2 copy of the id_rsa.pub generated in a machine to B machine, assuming copy to the temporary directory of B machine, such as:

Scp/root/.ssh/id_rsa.pub root@218.242.214.20:/tmp

3 with root account login B machine, into its home directory, create Authorized_keys files, and set the right permissions.

CD ~/.ssh

Cat/tmp/id_rsa.pub >>authorized_keys

chmod Authorized_keys

Rm-f/tmp/id_rsa.pub

4) test

On a machine to go to root account, try to log on to B machine. See if you don't want the password.

Description

Authorized_keys file permissions are important, and if set to 777, then you need to provide a password when you log in.

Remember to delete the id_rsa.pub in the temporary catalogue, and develop a good habit.

This method is tested on red Hat9.0.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.