Transfer Files Securely Over the Network

15 minutes
  • 4 Learning Objectives

About this Hands-on Lab

Among a system administrator’s duties is having to transfer files between systems. But sending files across a network can be a security problem, so we need to encrypt things using the tools available with SSH in order to keep our data safe while it’s in transit.

This activity will get us familiar with secure file transfers using SSH-based tools, like `scp` and `rsync`. Once this activity is complete, we’ll know when to copy files or to synchronize them, and understand the difference between “pushing” and “pulling” file transfers over the network securely.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Recursively List the opt Directory on server1 and server2

Once we’re logged in, let’s take a look at the directories we’ve got to work with:

Use ls -lR /opt/ locally on server1, and then execute it remotely on server2 with ssh:

ls -lR /opt
ssh server2 ls -lR /opt
Securely Copy the /opt/myapp Directory from server1 to the /opt Directory on server2

Now let’s use scp to recursively copy /opt/myapp on server1 into /opt on server2. The -r option makes it recursive, and -p makes it preserve time stamps and permissions. Since we should be logged into server1, we can omit the host portion of the source directory:

scp -rp /opt/myapp server2:/opt
Synchronize the /opt/myapi Directory from server2 with server1

We can use the rsync command to pull the /opt/myapi directory on server2 into /opt on server1:

rsync -aP server2:/opt/myapi /opt
Verify That the /opt/myapp and /opt/myapi Directories Are the Same on server1 and server2

To make sure everything is in sync, we can run ls -lR /opt/ locally on server1 and execute it remotely on server2 with an ssh command. Then we can use the rsync command to verify that the content, time stamps, and permissions are the same:

ls -lR /opt
ssh server2 ls -lR /opt
rsync -naP /opt/ server2:/opt

Additional Resources

We have been provided with two servers and the cloud_user user credentials to connect to both. On server1, a directory called /opt/myapp contains the configuration files that are needed on the server2. We can use scp to copy this directory recursively, pushing it from server1 to server2.

On server2, there is a directory called /opt/myapi that should be synchronized with the /opt/myapi directory on the server1. We'll use the rsync command to synchronize by pulling /opt/myapi from server2 to server1, overwriting any existing files that might be on server1.

To verify that the activity is complete, we'll recursively list the /opt directory on both servers to see that they contain the same content for /opt/myapp and /opt/myapi directories.

Logging In

Use the credentials on the hands-on lab overview page to get logged into server1 as cloud_user. The password for server2 should be the same as for server1.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!