Transfer Commands (Demo)
Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or
Already have an account? Sign In »

Video Transcription
00:00
>> Hey Cybrarians. Welcome back to
00:00
the Linux plus course here at Cybrary.
00:00
I'm your instructor Rob Gills.
00:00
In today's lesson, we're going
00:00
to discuss transfer commands.
00:00
Now upon completion of the lesson today,
00:00
you're going to be able to determine when to use
00:00
a transfer command, versus just
00:00
using a regular file or directory option.
00:00
We're going to use the scp, and rsync commands.
00:00
When you're looking to move a file or
00:00
directory for one computer,
00:00
like one Linux system to another Linux system,
00:00
you're going to need to use a transfer command.
00:00
But if you're just moving a file around
00:00
a specific Linux system in
00:00
the same file system, or in the same Linux system,
00:00
you're going to use an operation such as
00:00
a copy, or move operation command to do that.
00:00
The transfer commands that are covered on the Linux
00:00
plus exam are scp and rsync.
00:00
Let's check out these two with some demo time.
00:00
[NOISE] Here we are over in our CentOS environment,
00:00
and the first command
00:00
>> we're going to look at over here is
00:00
>> the secure copy command, or scp for short.
00:00
Scp is just a feature of the SSH protocol suites,
00:00
so we have to install anything out of the ordinary.
00:00
SSH is on your Linux machine, great.
00:00
You've already got a secure copy, you're good to go.
00:00
Now, scp is used to copy
00:00
small files from one machine to another.
00:00
For larger files or directories,
00:00
we're going to want to use something like rsync,
00:00
and we'll talk about that next.
00:00
The scp command itself is pretty basic.
00:00
We'll use it here to copy a file from CentOS to Ubuntu.
00:00
The syntax is just going to be scp,
00:00
[NOISE] and then the file that you want to
00:00
copy, and the remote server you want to copy to,
00:00
and then the path and the remote server where you're
00:00
going to place the file that you're copying.
00:00
For rsync, let's
00:00
go to my home directory,
00:00
>> and I think we're actually there.
00:00
>> Let's do a PWD, and we're in my home directory.
00:00
Let's just grab the Alpha source file
00:00
again, and we'll copy it over to Ubuntu.
00:00
Now on this system, let's just display as the host.
00:00
I've actually just added an entry here for Ubuntu.
00:00
That's a shortcut, so I don't actually need
00:00
to know the IP address for it.
00:00
I've set that same thing up on
00:00
the Ubuntu systems, so that we can go back and forth.
00:00
It already knows the location and
00:00
the IP addressable systems because it's an empty host.
00:00
That's a nice shortcut in case
00:00
>> you ever need to use that.
00:00
>> We'll just refer to the Ubuntu system as Ubuntu,
00:00
even though it's actually called Ubuntu 20,
00:00
because that's the name that
00:00
>> I gave it in the host file.
00:00
>> If we go on SSH to Ubuntu over here,
00:00
we're going to land in my home directory.
00:00
That's because we're SSH into Ubuntu
00:00
from my user, from Rob.
00:00
If we do a present working directory,
00:00
we see LS home Rob, and if you look in here,
00:00
we see a bunch of files, but we don't see
00:00
here is Alpha sort. Let's go back.
00:00
Remember we're going to grab the Alpha sort
00:00
file, and it's in this directory already,
00:00
so you don't need to specify the entire path,
00:00
we can just say we want to copy over Alpha sort,
00:00
and we're going to send that over to Ubuntu,
00:00
and we're going to put it in home Rob.
00:00
Now when we hit "Enter" it's copied over,
00:00
we can see it 100 percent of it's copied over,
00:00
it copied over about 81 bytes.
00:00
It copied over at a speed of 8.8 kilobytes per second,
00:00
and it took less than a second.
00:00
Pretty small file, so that was nearly instantaneous.
00:00
We can do an SSH into Ubuntu.
00:00
Now when we go in here, again,
00:00
we're in my home directory, and we see that
00:00
Alpha sort file has been copied over.
00:00
The nice thing about SCP is
00:00
that we can go in the opposite direction.
00:00
We can connect to another server and copy
00:00
a file to S. For instance,
00:00
here we could do an SCP,
00:00
we can specify the remote server that we want to
00:00
copy from, the path where the file that we
00:00
want to copy lives on the remote server, and then the
00:00
local file location we want to copy to on this system.
00:00
Let's take a look here.
00:00
We have a file in here called Ubuntu file.
00:00
Let's do a cat on Ubuntu file in this system.
00:00
I'll just clear the screen here.
00:00
We can see that this file says, "Hi,
00:00
I'm from Ubuntu 20". Let's get out of here.
00:00
I'm just hitting "Control D" to
00:00
exit out, and go back to CentOS.
00:00
If I do an LS here,
00:00
you can see that we don't have Ubuntu file.
00:00
It's not on the system yet.
00:00
Nothing up my sleeves.
00:00
No tricks here. What we'll do is we'll copy
00:00
that file from the Ubuntu machine, to this system.
00:00
We can do an SCP from Ubuntu in
00:00
the home Rob directory
00:00
of the file that we called Ubuntu file,
00:00
and we're just going to put it here.
00:00
Now, that is just a shortcut to say here, or it
00:00
just means put the file in this directory.
00:00
When you hit "Enter" that's copy done,
00:00
again, we can see 100 percent is copy done.
00:00
It's about 25 bytes.
00:00
It was 21 kilobytes per second,
00:00
and it took zero seconds to copy.
00:00
You do an LS and now we see the Ubuntu file.
00:00
Just to verify that we didn't do
00:00
>> any merge for anything,
00:00
>> we do a cut, and we see that has the same contents
00:00
of the file that we just looked at on our
00:00
>> Ubuntu system.
00:00
>> The only other option that we really
00:00
need to know about SCP is that we
00:00
can't copy directories, unless we use an r option.
00:00
R option is the recursive option.
00:00
Use the copy of directory.
00:00
If we try to copy without it,
00:00
it'll give us an error message.
00:00
For instance, if we're still here in home Rob,
00:00
and if you recall, we have this subdirectory
00:00
>> right here.
00:00
>> If we want to copy subdirectory over to
00:00
Ubuntu, and then put it into my home directory,
00:00
it's going to give us an error message.
00:00
It's going to say that SCP,
00:00
we can't copy this over,
00:00
some directory is not a regular file and they're right,
00:00
it's not a regular file, it's a directory.
00:00
We have to use the -r option to
00:00
recursively copy that file. Let's try that.
00:00
You know what, we're getting a permission denied issue
00:00
here, because there is no home directory.
00:00
That's a typo on my part.
00:00
You do scp -r somedir
00:00
Ubuntu home Rob and hit "Enter", and there we go.
00:00
It's created that honest for us on the Ubuntu system.
00:00
Now if we were to go an SSH back into Ubuntu,
00:00
and then just do an LS,
00:00
we're going to see that we also have
00:00
some directory here as well.
00:00
Now the next command we want to talk
00:00
about is the rsync command.
00:00
Rsync is used to remote sync or
00:00
copy a file or directory between servers.
00:00
The power of rsync is that it can just copy
00:00
changes that have happened
00:00
since last time the command is run.
00:00
It copies just the changes between files,
00:00
>> and directories,
00:00
>> keeping both copies in sync, hence rsync.
00:00
At heart, the rsync command can be run
00:00
basically just like RCP or SCP.
00:00
For instance, if we wanted to do an rsync with
00:00
a directory that's here on
00:00
Ubuntu back to CentOS, we can do that.
00:00
We deal with basically the exact same syntax.
00:00
If we look right here, we see we have
00:00
the Ubuntu directory. Let's clear our screen.
00:00
Let's do an LS, so we have
00:00
>> a little bit more real estate
00:00
>> to work with and to do
00:00
a copy or a sync of that back to the CentOS system,
00:00
we do rsync -r and we specify that we want
00:00
to grab ubuntuDir in the system.
00:00
We're going to copy that to CentOS.
00:00
We're going to put that in the home rob directory.
00:00
Then I'm going to need to type in
00:00
the passphrase for my SSH key here.
00:00
But that's done.
00:00
Now if we go back to CentOS
00:00
here and we do an LS in CentOS,
00:00
we can see that we have the Ubuntu directory right
00:00
here as well as the Ubuntu file.
00:00
The other thing that we should know though,
00:00
is that our sync is
00:00
really like infinitely more powerful than SCP.
00:00
Let's go back to Ubuntu real quick.
00:00
As you're over here in CentOS,
00:00
let's just do an LS -al on ubuntuDir.
00:00
What we can see is that that file was created today,
00:00
April 24th, 23,
00:00
24, and we see that the contents of
00:00
the directory you don't want is
00:00
this first subdirectory in that file.
00:00
Let's go back to Ubuntu.
00:00
Then we'll do an ls -al on ubuntuDir here.
00:00
We can see that that was actually
00:00
created on December 7th.
00:00
We didn't preserve the timestamps
00:00
when we needed the rsync.
00:00
Well, we can preserve timestamps
00:00
with rsync just like we would with
00:00
a regular copy by using the a for archive option.
00:00
Let's actually just use a little short one-liner here,
00:00
we're going to go to CentOS and we're going to remove
00:00
the directory home rob ubuntuDir.
00:00
That's going to remove that from the CentOS system,
00:00
not from this system, but from CentOS,
00:00
and that's one of the nice things about SSH.
00:00
You can actually pass in
00:00
just a little one-liner bash commands
00:00
right through SSH without
00:00
actually having SSH to a server.
00:00
Then it just returns you to
00:00
the shell on the server that you're in it from.
00:00
Super-helpful. We've removed that.
00:00
Now if we run the rsync command
00:00
again that we ran previously,
00:00
and I'm just going to hit the up arrow until
00:00
we get back to it.
00:00
I'm going to actually add the a
00:00
for archive option to the front of this,
00:00
and we'll move this file back over to CentOS.
00:00
I'll type in my SSH key again.
00:00
Now if we just exit out of here and go
00:00
back to our CentOS system.
00:00
Now I do an ls -al ubuntuDir,
00:00
we can see that it has the timestamp preserve,
00:00
December 7th at 21:55,
00:00
just like here, December 7th at 21:55.
00:00
Now another really powerful combination
00:00
with rsync is azvh.
00:00
That's SSH back to Ubuntu.
00:00
Actually, before we do that,
00:00
let's just go ahead and remove ubuntuDir from here.
00:00
Dir -r, remove that thing from there,
00:00
SSH back to Ubuntu.
00:00
What we're going to do now instead of
00:00
just doing an rsync ar,
00:00
we're going to do an rsync azvh.
00:00
I'll tell you the reason for this.
00:00
A for archive, that's going to transfer,
00:00
is going to preserve all the permissions,
00:00
all the timestamps, everything we just saw.
00:00
Z is going to copy it,
00:00
and it's going to copy it compressed
00:00
so that it takes less time to copy.
00:00
The v option displays output,
00:00
it shows you all of the files that
00:00
>> are being transferred.
00:00
>> Then the h output gives you
00:00
>> a nice human-readable output,
00:00
>> especially like at the bottom,
00:00
it gives you a little result.
00:00
We remove the Ubuntu directory on CentOS.
00:00
Let's run this again from
00:00
here and move it back to CentOS.
00:00
We'll type in my SSH key password again in the system.
00:00
Now we can see that it
00:00
tells us what it's actually doing,
00:00
it's sending an incremental file list.
00:00
Here's the file that's moving.
00:00
It's going to move the Ubuntu directory.
00:00
It's going to move the subdirectory dir 1,
00:00
the subdirectory dir 2,
00:00
the subdirectory dir 3.
00:00
It's on 145 bytes received 32 bytes
00:00
and took less than a second,
00:00
instantaneous because there's nothing
00:00
in these files. They're all just for example.
00:00
That's pretty much all we really
00:00
need to know about rsync.
00:00
Rsync is super-helpful.
00:00
It has a lot of great options,
00:00
so definitely invest more time and trying
00:00
other options if you have a machine to play on.
00:00
But for the purposes of the Linux plus exam,
00:00
that's really all we need to know about SCP and rsync.
00:00
With that, we reach the end of this lesson.
00:00
In this lesson,
00:00
we covered performing file
00:00
and directory transfer operations
00:00
with SCP and rsync.
00:00
Thank you so much for being here and I look
00:00
forward to seeing you in our next lesson.
Up Next
Instructed By
Similar Content