Note: This is an RHCSA 7 exam objective.
There are many ways to transfer files from a system to another. Here we will consider the scp command that relies on SSH that is normally installed on most hosts.
Transfer of a local file
First, we create a file called loc locally:
# cd; echo "This is a test." > loc
To transfer the local file to a remote host (here called centos) into the root‘s home directory, type:
# scp loc root@centos:loc root@centos's password: your password loc 100% 16 0.0KB/s 00:00
Note: By default, the file is put into the user’s home directory but it is possible to give a complete path.
To copy all the files from a specified directory, type:
# scp /etc/ssh/* root@centos:/tmp root@centos's password: your password moduli 100% 236KB 236.5KB/s 00:00 ssh_config 100% 2123 2.1KB/s 00:00 sshd_config 100% 4442 4.3KB/s 00:00 ssh_host_ecdsa_key 100% 227 0.2KB/s 00:00 ssh_host_ecdsa_key.pub 100% 162 0.2KB/s 00:00 ssh_host_rsa_key 100% 1679 1.6KB/s 00:00 ssh_host_rsa_key.pub 100% 382 0.4KB/s 00:00
Note: If directories appear in the list created by the *, there are not transferred: you get a “not a regular file” error (use the tar command to transfer directories).
Transfer of a remote file
Conversely, it is possible to transfer a file from a remote host.
On the centos host, create the rem file in the /tmp directory:
# cd /tmp # echo "This is another test." > rem
Locally, to transfer the file, type:
# scp root@centos:/tmp/rem rem root@centos's password: your password rem 100% 22 0.0KB/s 00:00
Source: RHEL 7 System Administrator’s Guide.