Home Linux Backup Tools How to Perform a Remote Linux Backup Using SSH

How to Perform a Remote Linux Backup Using SSH

Secure Shell or SSH is responsible for successful network communication between two remote computers. For a Linux system administrator, this networking tool is the perfect solution for remote server/machine access over unsecured networks. For you to initiate and complete data backup under any Linux platform, you need to achieve two things:

  • Secure network access to the remote machine with data you wish to backup.
  • Secure data transfer mechanism to move your targeted data to a specified remote machine or backup directory.

Since this article objectifies remote data backup using SSH, it is important that the data transfer mechanism we choose to go with has undisputed support for SSH network protocols.

SCP for Secure Data Transfer

SCP (Secure Copy) is a reputable data transfer mechanism between two remote machines. Before data transfer takes place between the two remote machines, a Linux administrator has to be able to comfortably use one machine (local) to access the other machine (remote).

[ You might also like: How to Rsync Files Between Two Linux Servers Automatically ]

SCP first accomplishes local to remote machine access through the SSH network protocol before initiating any data transfer. With SSH protocol, access to a remote machine requires system username and password authentication.

This remote server access can be accomplished with a command implementation similar to the following:

$ ssh [email protected] 
Connect to Remote Linux
Connect to Remote Linux

From here, the user attempting remote access is required to key in a user password associated with the username (ubuntu) before remote server access is authenticated.

[ You might also like: How to Pass Password to SCP Command in Linux ]

However, this article recommends passwordless access to your remote machine/server through generated SSH key pairs that exist on both the local machine and remote machine.

Connect to Remote Linux Without Password

On the local computer, generate the needed SSH key with the following command:

$ sudo ssh-keygen -t rsa 

On the resulting prompt, remember to skip the Enter passphrase: step by hitting [Enter] on the keyboard.

Create SSH Key in Local Linux
Create SSH Key in Local Linux

The remote server needs a copy of the SSH key.

$ sudo ssh-copy-id [email protected]
Copy SSH Key in Remote Linux
Copy SSH Key in Remote Linux

Now connect to remote Linux server without a password SSH access.

$ sudo ssh [email protected]

You should automatically gain access to the remote server via SSH.

Connect to Remote Linux Without Password
Connect to Remote Linux Without Password

SCP Remote Linux Backup via SSH Protocol

Before you backup data to/from a remote server, make sure you are on the correct directory path on the local machine and that you are also familiar with the directory structure on the remote/server machine.

On the local machine:

$ pwd
$ ls 
Listing Local Linux Files
Listing Local Linux Files

On the server/remote machine:

$ pwd
$ ls 
Listing Remote Linux Files
Listing Remote Linux Files

To perform SCP remote Linux backup via the SSH protocol, we would implement the following command syntax:

Backup Local Directory to Remote Linux

$ sudo scp -r path/to/local/directory/with/useful/data user@remote_server_ip:/path/to/remote/backup/directory

The above command syntax translates to the following:

$ sudo scp -r /home/dnyce/LinuxShellTips [email protected]:/home/ubuntu/LinuxShellTips_Backup
Backup Local Directory to Remote Linux
Backup Local Directory to Remote Linux

From the above command, we have successfully backed up a local machine directory to a remote machine directory by implementing the SCP tool kit with SSH keys.

Backup Remote Directory to Local Linux

To create a backup from the remote server to your local machine, the syntax to use will look like the following:

$ sudo scp -r user@remote_server_ip:/path/to/remote/directory/with/useful/data path/to/local/backup/directory/ 

The implementation of the above syntax translates to the following:

$ sudo scp -r [email protected]:/home/ubuntu/LinuxShellTips_Backup /home/dnyce/LinuxShellTips 
Backup Remote Directory to Local Linux
Backup Remote Directory to Local Linux

Whether you are after local-to-remote or remote-to-local backup solutions, SCP’s inheritance of SSH keys and network access protocols makes remote data backup effortless.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

2 thoughts on “How to Perform a Remote Linux Backup Using SSH”

Leave a Reply to Ravi Saive Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.