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 onserver1
, and then execute it remotely onserver2
withssh
: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
onserver1
into/opt
onserver2
. The-r
option makes it recursive, and-p
makes it preserve time stamps and permissions. Since we should be logged intoserver1
, 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 onserver2
into/opt
onserver1
: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 onserver1
and execute it remotely onserver2
with anssh
command. Then we can use thersync
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