How to Use SCP Command to Securely Transfer Files in Linux

SCP, i.e., Secure Copy is a remote file transfer program for Linux. It copies files by establishing an SSH connection and hence uses the authentication and security offered by SSH.

In this article, we’ll show you how to copy files remotely using SCP. Note that, the user needs to know the password of the user in the remote computer(s) he is trying to copy files from or to. Or else SSH passwordless RSA authentication must be already configured between the computers. Also, needless to mention, SSH daemon should also be running on remote computers.

To learn how to configure SSH to connect without a password and how to install SSH daemon, check out our article on using SSH in Linux.

Transfer files from and to a Remote Computer

To transfer a local file to a Remote computer, run:

scp <local_file_path> <remote_user>@<remote_hostname>:<remote_path>

For example:

scp test.txt root@

Similarly, to transfer file from a Remote computer to a local computer, run:

scp <remote_user>@<remote_hostname>:<remote_path> <local_path>

For example:

scp root@ /home/abhi/dev/scp_test/test_remote

Transfer files between two Remote Computers

Similar syntax, as shown above, is used for the transfer of files between two remote computers. Here, both remote computers either need to be configured for passwordless SSH login, or the user needs to know the password of both remote computers.

scp root@ root@

Note that the user with which we are establishing an SSH connection (root) must have write permissions in the target folder (/root). Otherwise, the command throws permission denied error.

There are many more options in SCP to establish a connection using an identity file, to pass SSH options, etc. You can find these in the SCP man page.

man scp

🍻 Cheers!

Leave a Reply