Hey everyone and welcome back. So in the previous nugget we had talked about our SSH client
configuration. We also discussed how SSH can be used to ultimately wrap things like FTP
so that the regular unsecured FTP can now be transported using encryption. So how about we
dive in and begin getting hands on then shall we? So what I will do here is if I clear the screen here
in fact let me just change the size right here. So we have server one and on the right here we
have server two. Let me clear the screen on that. There we go. So as we know we already can SSH from
one server into the next. So again if I try to SSH from server two and I go into the IP address
of number one which is 4.26. We can type in the password bam we're in who am I and we can see
we are in server one. No problem at all and no big revelation at all. So if we close the connection
now what I want to first do is to show you how we can actually use something called secure copy to
ultimately copy files from one server to the other and have that transaction be securely
encrypted so that any potential e-droppers could not actually see what the data that is being
passed between the servers actually is. So check this out then. What I will do here is let's maybe
go on to server one then. So on server one we can see here I'm in my home directory. I can do an ls.
Now if I want to just create a particular file let's maybe put it in I don't know let's just go
for the documents directory. So cd into the docs we do an ls. We do not have any particular file
here what I will do is I will actually create a file. So I'll just call this maybe my personal
stuff.txt okay. Just say this is some personal file on server one. Okay so let's save you write it out
and escape if we cat this particular file we can see we have the contents here. What I now want to
do is I want to be able to take this file right here and move it into server two and again I want
this transaction to be encrypted over ssh. So what I'm going to do here is I'm going to use the scp
command. Now the syntax is going to be as follows. I'm going to say on my server one where the actual
file resides. I'm going to say scp and then I'm going to specify the file which I want to copy now
the absolute path and the relative path is still in play here because I happen to be within. Again
I show you here the documents directory where this file resides. I can just specify the name of the
file otherwise if I was in a different location I would have to specify the absolute path for that
particular file but like I say we're in this directory so no need I will just specify the
name of the file and you know what let me just get a little bit more real estate here and now what I
want to do is I want to specify where it is I want to send this so I'm going to log in to
server two here so the ip address or rather the username should I say to log in with is ipv0 because
that is the user here on server two and I'm going to use server two's ip address which is 1921684.28
now what I'm going to do is have a colon and a forward slash and now what I have to do is specify
where abouts in that server do I want to copy this file so if I go into server two what I could do
is let's just say I wanted to copy it to let's maybe say the downloads directory it doesn't have
to be here you can copy it anywhere you wish but the point is here is the actual path okay so what I
can do here is actually just specify this path here so I can say home and we can see it's ipv0 so
I'll just say ipv0 and the directory I'm going to put this into is the downloads directory okay now if
I just hit enter here we can see the banner right here I'm going to type in my password for server two
hit enter now we can actually see this is the file that has been copied over and we can see 100%
and a little summary of the connection crucially though if I go into this directory which I am
and I do an ls now notice this file exists on this server and we can actually cut this by opening it
there we go this is some personal file on server one but now it's been copied to server two now there
are a few variations which you can use within here for example let's just do the same thing I'll do an
ls in fact an ls would be helpful and I just remove this file so it's no longer on the server
let's say I wanted to copy it once again now what I can do here is if I clear the screen back on server
one and I arrow up if I just specify the name of the directory the file is going to be copied with
the same name however if within this directory I just give it a new name if I just call this let's
just say bladot txt and I hit enter again type in the password for server number two hit enter
the connection happened again we can see the summary we have sent this file but notice this time in
this directory here on server two the file is called bladot txt it was renamed but the contents
are exactly the same similarly we can also still make use of again I'll just remove this one more
time so we don't have it we can also make use of our variables so what do I mean as opposed to having
to specify home ipv0 what I could do is I could just delete this and I could use my dollar sign home
pretty much saying that just copy this directly to that server's home directory and again if I
wanted to rename it I could just say whatever I wanted to rename it rename dot txt doesn't matter
for now I'll just leave it at the home directory so if I hit enter and just do my password
enter again again we've transferred that file once again if I do a pwd we're in the wrong
directory so I'll change directory into the home where we are I do an ls and now we can see on server
two once again that file has indeed been transferred and again a stress this has been transferred using
ssh and fully encrypted now with scp we do have more options more switches if I do a man scp right
here if I just scroll on down we can see some different options we have we can use ip4 addresses
we can just use ipv6 we can specify particular ports to target we can preserve modification
times and access times from the original file which can be very useful we can also say dash v
for for bose mode we can do dash q to dampen the output and have a quiet mode so just one last time
what I'll do is I will do scp and I'll use a particular switch let's just say dash v for verbose
this time I'll put it in the user's home directory but I'll rename the file let's just say
blad2.txt and that that matters if I hit enter look at the information that has just been
splashed onto the screen much much more verbose as we expect so if I type in the password one more
time hit enter we can see the connection right here the transfer has happened I go to the user's
home directory once again notice we now have this blad2.txt and no surprise is what the content is
actually going to be it's going to be the same content there we are right there so that's using
scp the other one we can use is sftp which is file transfer protocol this time again using that ssh
encryption the difference here is that with scp we actually make the transfer from the point of view
that we are pushing the file from where it happens to reside to another server when we're using sftp
we do it the reverse way but ultimately pulling the file from the server into the client who's
receiving the file so to do the same type of transaction let's go and I'll clear the screen
to an ls we have my personal stuff and on this directory here I'll just remove these text files
by saying rm wildcard.txt ls so now we no longer have that file so as opposed to get on to the
command line of server one and pushing that file to server two we're going to go on to the command
line of server two and pull the file into server two using sftp so what I will do is I will use
the command sftp and I will give the username of server one and the ip address of server one which is
4.26 if I hit enter I'm going to have to log in if I just type in the password for server one right
hit enter we now have this sftp connection I can do an ls we can see a listing of what is present
here I can go into the documents directory do an ls here is the file which I want to pull from server
one onto my local machine on server two what I can then do is just say get my personal stuff.txt
and if I hit enter we've now fetched that particular file and what I can do here is I can just say
quit and do an ls notice now that my personal stuff again is back on our directory so I can say
cat my personal stuff and the contents is indeed right here the difference again here is that this
time we had to log in from server two as the client and pull in that file using the credentials
and the ip address of server one whereas with sftp we're doing the inverse the ultimate
overriding principle though is that both connections were wrapped within that ssh connection fully
encrypted and protected from eavesdroppers now similarly with sftp we can do the same
type of thing if I just finally remove again this file one last time my personal stuff I can say
sftp as we did before log into server one type in the password ls let's go back into the documents
directory of server one ls again here is my personal stuff I can get it by saying my personal
stuff and if I want to change the name what I could just do is just specify the name I want to
pull it in as let's just say blah stuff blah and clearly run out of any type of creativities if I
hit enter now we're going to copy this document I will say quits we do an ls but now the file has
been renamed blah stuff blah and no surprises once again the contents are still the same so that
really is us for using sftp and the scp function as ssh clients the next thing we'll be looking at
is how we can use our ssh keys to log into our devices without having to specify our passwords
and that's what we'll be looking at in the very next nugget so I hope this has been informative
for you and I'd like to thank you for viewing