Warning: SCP Protocol has been deprecated in favour of SFTP protocol. Reason: multiple security risks.
In this article, we cover how to copy files remotely using scp command. We used scp command to securely transfer files between different hosts on a network. In other words, we could transfer files from a local host to remote host & vice versa. Apart from that, we could also transfer files between two remote hosts.
Use scp to copy files remotely
A regular user can execute the command if he/she has required read/write permissions for both local as well as remote hosts.
I. If you want to copy a file to remote host from local host then,
$ scp <file-name> username@to-host:/remote/host/directory
For instance, if we want to copy abc.txt file to techpiezo user at IP – 192.168.1.115. And, the directory where the file will be copied – /home/techpiezo/Downloads. In that case, command will be –
$ scp abc.txt [email protected]:/home/techpiezo/Downloads
If you connect to remote host the first time then, it would state – authenticity of host can’t be established. And, it shows ED25519 key fingerprint and if enter yes. It would permanently add the remote host to the list of known hosts. Thereafter, it would prompt for the targeted host’s password.
II. If you want to copy a file from remote host to local host then,
$ scp username@from-host:/remote/host/file /local/host/<file-name>
Continuing with the above example, file – abc.txt; user – techpiezo; IP – 192.168.1.114. And, the directory from where the file is copied – /home/techpiezo/Documents.
$ scp [email protected]:/home/techpiezo/Documents/abc.txt /dev/shm/copiedabc.txt
In conclusion, we have covered how to use scp to copy files remotely.