website logo

Last Updated:

Securely Copy File Across Different Hosts Using SCP

Secure Copy Protocol of SCP is a simple CLI tool to send and receive files across the internet. SCP uses SSH (Secure Shell) technology to establish connection with the remote host.

You can either use a password based authentication or public private key pair to establish the connection with the remote host. Read this blog to learn about how to generate and install SSH key pair in your Linux machine.

SCP is secure by default. It encrypt the file during transfer and securely decrypt it in the destination.

Copy local file to remote server

If you are familiar with the cp command on Linux to copy files in your file system, then scp works very similarly.

scp [source] [desctination]

To copy a local file to the remote server, the SCP command should be:

scp todo.txt user@ipAddress:/home/user/

In the above example, you copy the todo.txt file from your local file system to the remote host user@ipAddress and place the file inside the /home/user/ directory.

Copy remote file to local machine

To copy a remote file to your local file system, the SCP command should be:

scp user@ipAddress:/home/user/todo.txt .

In the above example, thetodo.txt file present inside the /home/user directory of the remote host is copied to the current working directory . inside our local file system.

Copy Directories using SCP

To copy a directory using SCP, use the recursive -r flag.

scp -r test.txt user@ipAddr:/home/user/


In this blog, you have learned how to use SCP CLI tool to copy file or folder across different host machines. Feel free to read other blogs to learn more about different fields of programming.

See Also