If you would like to transfer files between Unix or Linux computers securely without having to worry about any unauthorized viewings, you’d need to do that with the SCP commands. SCP means secure copy. It is a command-line tool used to copy or transfer files and directories across Unix and Linux systems securely.
For example, if you want to copy files to Linux, and you’re worried about prying eyes on the network having access to your files, you can easily use the SCP commands which password authentication. SCP commands SSH to transfer data and that files and passwords are encrypted to avoid unauthorized viewings.
To understand how to use SCP commands, it’s important to have a basic understanding of SCP syntax, as knowledge of SCP syntax helps you to understand the systemic orderly arrangement of SCP commands and helps you understand the rules for forming them.
SCP syntax assumes this form:
scp [OPTION] [user@]SRC_HOST:]file1 [user@]DEST_HOST:]file2
There are also some designated SCP options that regulate SCP commands behavior:
Some important points:
Because SCP commands use SSH, to transfer data or copy files to Linux would require the use of authentication passwords for security purposes. To copy the file to Linux systems, you’d need to have read and write permissions on the source file and on the target system respectively.
Adequate care and attention should be given to files that have the same name and location on the source system and the destination system because copying such files from one Linux system to another using the SCP commands will overwrite them without notifying the operator.
SCP commands use the “: ” (colon) to differentiate local locations from remote ones.
Now that you have a basic understanding of SCP syntax, let’s get on with 14 examples of how to use SCP commands to securely transfer or copy files to Linux.
[user@linux ~]$ scp [email protected]:/root/Technical-Doc.odt /tmp
[email protected]’s password:
Technical-Doc.odt 100% 109KB 3.1MB/s 00:00
[user@linux ~]$ ls -l /tmp/Technical-Doc.odt
-rwx——. 1 user user 1135521 Oct 19 11:12 /tmp/Technical-Doc.odt
[user@linux ~]$
This example of how to copy files to Linux from a remote system under the /tmp folder.
[user@linux ~]$ scp jdk-linux-x64_bin.rpm [email protected]:/opt
[email protected]’s password:
jdk-linux-x64_bin.rpm 100% 10MB 27.1MB/s 00:00
[user@linux ~]$
[user@linux ~]$ scp -r Downloads [email protected]:/opt
To confirm if download folder has been copied to a remote system, use this command:
[user@linux ~]$ ssh [email protected] “ls -ld /opt/Downloads”
drwxr-xr-x. 2 root root 75 Oct 19 12:10 /opt/Downloads
[user@linux ~]$
# scp user@remote_hosts1:/<files_to_transfer> user@remote_host2:/<folder>
For example:
# scp [email protected]:~/backup-Oct.zip [email protected]:/tmp
# ssh [email protected] “ls -l /tmp/backup-Oct.zip”
-rwx——. 1 root root 747438080 Oct 19 12:02 /tmp/backup-Oct.zip
[user@linux ~]$ scp install.txt index.html jdk-linux-x64_bin.rpm [email protected]:/mnt
[email protected]’s password:
install.txt 100% 0 0.0KB/s 00:00
index.html 100% 85KB 7.2MB/s 00:00
jdk-linux-x64_bin.rpm 100% 10MB 25.3MB/s 00:00
[user@linux ~]$
user@linux ~]$ scp -v jdk-linux-x64_bin.rpm [email protected]:/opt
Executing: program /usr/bin/ssh host 10.20.10.8, user root, command scp -v -t /opt
OpenSSH_7.8p1, OpenSSL 1.1.1 FIPS 11 Sep 2018
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Reading configuration data /etc/ssh/ssh_config.d/05-redhat.conf
debug1: Reading configuration data /etc/crypto-policies/back-ends/openssh.config
debug1: /etc/ssh/ssh_config.d/05-redhat.conf line 8: Applying options for *
debug1: Connecting to 10.20.10.8 [10.20.10.8] port 22.
debug1: Connection established.
…………
debug1: Next authentication method: password
[email protected]’s password:
[user@linux ~]$ scp -l 500 jdk-linux-x64_bin.rpm [email protected]:/var
user@linux ~]$ scp -r -C Downloads [email protected]:/mnt
[root@linux ~]# scp -c 3des-cbc -r Downloads [email protected]:/root
In the example above, 3des-cbc is the cipher name you want to use
[user@linux ~]$ scp -P 2022 jdk-linux-x64_bin.rpm [email protected]:/var
[user@linux ~]$ scp -F /home/user/new_ssh_config -r Downloads [email protected]:/root
[email protected]’s password:
jdk-linux-x64_bin.rpm 100% 10MB 16.6MB/s 00:00
backup-Oct.zip 100% 713MB 41.9MB/s 00:17
index.html 100% 85KB 6.6MB/s 00:00
[user@linux ~]$
[user@linux ~]$ scp -p jdk-linux-x64_bin.rpm [email protected]:/var/tmp
jdk-linux-x64_bin.rpm 100% 10MB 13.5MB/s 00:00
[user@linux ~]$
[user@linux ~]$ scp -i my_key.pem -r Downloads [email protected]:/root
[user@linux ~]$ scp -q -r Downloads [email protected]:/var/tmp
[user@linux ~]$
An SCP means a secure copy. It’s a convenient way of ensuring the security of files while they’re being transferring from one Linux system to another using the SSH that allows for it to encrypt both files and passwords.
The SCP command has a variety of options that helps regulate SCP command behavior and undertake some tasks like copying directories and files recursively, modifying files, suppressing non-error messages, etc.
To make use of the commands, a basic understanding of the SCP syntax, and how they are applied is necessary, as has been shown in this article.