In the realm of systems administration, moving or copying files between systems is an essential skill. This article aims to guide you through copying files from one Linux system to another using two popular tools: SCP (Secure Copy Protocol) and Rsync.
Using SCP (Secure Copy Protocol)
The scp command-line utility is a file copying tool that uses SSH (Secure Shell) for data transfer. SCP allows files to be copied to, from, or between different hosts. It uses the same authentication and security as the SSH protocol.
Here’s the basic syntax of the SCP command:
scp [options] [user@]host_source:/file/path [user@]host_destination:/file/path
Let’s decipher this syntax:
- options: These are parameters that modify the behavior of the scp command.
- user@host_source:/file/path: This defines the user, source host, and file path of the file to be copied.
- user@host_destination:/file/path: This defines the user, destination host, and file path where the file will be copied.
To copy a file from one Linux system to another, follow these steps:
$ scp /path/to/source/file username@destination_host:/path/to/destination
It will prompt for the password of the destination host’s user. Once the correct password is entered, the file will start transferring.
Using Rsync
rsync (Remote Sync) is a most commonly used command for copying and synchronizing files and directories remotely as well as locally in Linux/Unix systems. The key advantage of rsync is that it only transfers the changed blocks and bytes, which makes it fast.
The basic syntax of rsync is:
rsync [options] source destination
To copy a file from one Linux system to another, using rsync, the command is as follows:
$ rsync -avz /path/to/source/file username@destination_host:/path/to/destination
The flags used above are:
- -a: Enables archive mode
- -v: Increases verbosity
- -z: Compresses data during the transfer
After executing the command, it will prompt for the password of the destination host’s user. Once the correct password is entered, the file transfer will start.
Both SCP and Rsync are effective tools for transferring files between Linux systems. For small files and infrequent transfers, SCP is a quick and easy option. For larger files, frequent transfers, or if you need to maintain file permissions, Rsync is the better choice.