RHEL7: Securely transfer files between systems.

Share this link

Note: This is an RHCSA 7 exam objective.

Presentation

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    

Additional Resources

In addition, you can watch this video by Sander van Vugt (5min) or read an article explaining the various scp options.

Source: RHEL 7 System Administrator’s Guide.

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 4.00 out of 5)
Loading...
One comment on “RHEL7: Securely transfer files between systems.
  1. salvador says:

    the following copies recursively all files and directories which are under /a/devel/ to the remote host:
    scp -r /a/devel/* 192.168.122.4:/a/d1/

Leave a Reply

Upcoming Events (Local Time)

There are no events.

RHCSA7: Task of the day

Allowed time: 10 minutes.
Create an EXT4 file system mounted under /vol based on a logical volume of 100MB.
Reduce the size to 60MB.

RHCE7: Task of the day

Allowed time: 10 minutes.
Set up a NFS server that exports the /opt directory in read-only mode.

Follow me on Twitter

Poll for favorite RHEL 7 book

What is your favorite RHEL 7 book to prepare RHCSA & RHCE exams?

View Results

Loading ... Loading ...

Poll for most difficult RHCSA 7 topic

What do you think is the most difficult RHCSA 7 topic?

View Results

Loading ... Loading ...

Poll for most difficult RHCE 7 topic

What do you think is the most difficult RHCE 7 topic?

View Results

Loading ... Loading ...