Linux Commands

How to Copy a File From one Server to Another in Linux Using scp Command

scp (secure copy) is a popular command line utility, widely used to transfer files from one server to another. The scp command offers the same authentication and services as the ssh commands and transfers files using the ssh protocol. You must have a host account or a key to transfer the files using this command.

In this guide, we will explain how you can quickly copy a file from one server to another using the scp command in Linux.

Copy Files from One Server to Another in Linux Using scp Command

The following is the general syntax of the scp command:

scp [options] source_file_location username@IP_destination_host:destination_file_location

In the above command, the source_file_location is the directory path for a file you want to send. The username is the name of destination host to which you want to send the file. IP_destination_host is the IP address of the destination host, while destination_file_location is the directory path of destination host where the source file is going to be saved.

The scp command can be used with different following options:

    • -p: it specifies the ssh port of the host.
    • -q: this option suppresses the progress.
    • -c: this option compresses the data for sending the host machine.
    • -r: recursively copy the directories.

Let’s copy the file sample.txt to the directory Documents of the host system pi@

scp /home/linuxhint/Documents/sample.txt pi@


Note: Don’t forget to add full path for both source and destination.

When you execute the above command, a question will pop up on your screen, answer with yes to continue the process.

Once the process is finished, go to the destination directory of the system, and you can easily locate the copied file there. In the above example, the sample.txt will be copied to the Documents directory of the system.

Bottom Line

The scp command in Linux securely transfers or copies the directories and files from one server to another. The scp command uses the ssh protocol for data transferring. This article provides a syntax and an example to transfer file from host to remote server.

About the author

Zainab Rehman

I'm an author by profession. My interest in the internet world motivates me to write for Linux Hint and I'm here to share my knowledge with others.