Using SSH and SCP

Video loading...

  • 0:02
    Using SSH and SCP with Addison Berry
  • 0:08
    Hey, there.
  • 0:09
    This Command Line Basics video is going
  • 0:10
    to be about SSH and SCP.
  • 0:13
    SSH stands for secure shell, and is a way for you to remotely
  • 0:18
    access a server and then have a full command line
  • 0:20
    access available to you.
  • 0:22
    And then, the other is SCP, which stands for secure copy.
  • 0:26
    And this is a great way to move files around back and forth,
  • 0:30
    and is much more secure than something like FTP.
  • 0:35
    We're going to start off in terminal.
  • 0:37
    My command line on my local machine,
  • 0:39
    which is is named beech, and I'm going to ssh so
  • 0:42
    that I can connect to a remote server.
  • 0:45
    And the first thing I need is the username on that server,
  • 0:48
    which is tester, and then @ and then put
  • 0:51
    the actual address of where I'm going.
  • 0:53
    Sometimes, this will be an IP address, but often times,
  • 0:55
    you can use the domain name.
  • 0:57
    Now, when I hit enter and tried to connect here,
  • 0:59
    it said it refused that because it wasn't connecting
  • 1:01
    to port 22, which is the default port for SSH.
  • 1:05
    Sometimes when you get connection information,
  • 1:07
    they'll tell you, you have a port number because
  • 1:09
    it's something other than 22, and that's important.
  • 1:13
    The way we add that information is,
  • 1:16
    beginning with my command here, I'm going to put a -p
  • 1:18
    for port and then just type in the number so I can connect.
  • 1:23
    And I'm just telling SSH specifically to use this port
  • 1:26
    on the server to get in.
  • 1:27
    When I do that, now it works.
  • 1:29
    It prompts me for my password, which I'll go ahead and type in.
  • 1:34
    Now I'm actually on my remote server.
  • 1:37
    I'm not on my local desktop anymore on this command line.
  • 1:40
    You can see this is telling me my location,
  • 1:42
    and it's not my local. So I have full command line
  • 1:45
    access now on a server, somewhere out in,
  • 1:48
    I don't know,
  • 1:48
    St. Louis?
  • 1:50
  • 1:50
    I'm not sure.
  • 1:51
    If I do a working directory here,
  • 1:55
    I can see I'm in my home directory.
  • 1:57
    I have a folder in here, and I can move around
  • 2:01
    and pretty much do what I want to from the command line,
  • 2:04
    given the permissions that I have for this particular
  • 2:07
    user on this server.
  • 2:08
    The thing I want to do now is actually go
  • 2:13
    and find something that I want to actually
  • 2:16
    download to my local machine from the remote.
  • 2:20
    I want to grab this files directory because there's a
  • 2:22
    bunch of files on the server.
  • 2:23
    I don't have them locally; I'm just going to copy those down.
  • 2:27
    Typically, you would probably use an FTP for that,
  • 2:29
    but we're going to use SCP because it's cooler.
  • 2:34
    I can go in and get an individual file if I wanted,
  • 2:39
    or you can go in and get an entire directory.
  • 2:44
    I'm going to want to get the files directory.
  • 2:46
    One thing we'll need to know is the path,
  • 2:49
    so I have this path in my prompt,
  • 2:52
    but if I do a working directory here,
  • 2:56
    I need the full path all the way from the root of the server.
  • 2:59
    I'm just going to copy this so I can paste it later,
  • 3:03
    so I don't have to remember all this and type
  • 3:05
    it in because that's a real pain.
  • 3:08
    I've copied the path to the thing that I want
  • 3:11
    on my remote server.
  • 3:12
    I'm going to exit, and that logs me out
  • 3:14
    of the remote server
  • 3:15
    and now you can see I'm back on my local machine.
  • 3:19
    Let me clear this out, and let's look at SCP.
  • 3:23
    OK, the first thing I'm going to want to do
  • 3:25
    is, like previously, I'm going to type the letters scp.
  • 3:27
    That's my actual command.
  • 3:30
    And then, before I start actually writing
  • 3:32
    it out for real, we need to put 2 locations in,
  • 3:36
    and we need to put from and then to.
  • 3:38
    That's the order they
  • 3:39
    have to go in, so wherever I'm copying from
  • 3:42
    and then where it's going to.
  • 3:45
    I'm copying from the remote server where I just was logged
  • 3:48
    in previously, so I need to give it the full information.
  • 3:51
    It needs to know what server and how to access it,
  • 3:54
    so I need to put in my user, @,
  • 3:56
    and then the address on the web, and then that's the server;
  • 4:01
    a colon to say, okay, that's the server information,
  • 4:05
    now where on that server am I going?
  • 4:07
    And that's where I'm going to paste in the path that
  • 4:09
    I had just previously copied.
  • 4:12
    I could just type in a particular filename.
  • 4:14
    If I just wanted one file, I could just put that in here,
  • 4:18
    but I actually want to get the whole files directory
  • 4:20
    so I'm going to leave it with what I've pasted.
  • 4:24
    And then the second part,
  • 4:26
    all of that is the from location.
  • 4:28
    The second part is to location.
  • 4:30
    I just want to download this locally to my laptop
  • 4:33
    onto the desktop, so that's just a local
  • 4:35
    path because I'm on my local machine and it knows
  • 4:38
    where that is.
  • 4:39
    I have this files directory I want,
  • 4:42
    rather than an individual file.
  • 4:43
    Like other things in the command line,
  • 4:47
    I need to tell the command to do this recursively
  • 4:50
    because otherwise it's just going to want 1 thing.
  • 4:52
    Let's walk through this command.
  • 4:55
    scp -r means recursive, because I'm getting a directory
  • 4:58
    instead of an individual file.
  • 5:01
    Then I'm saying this is the actual server that I want
  • 5:05
    to connect to; this is where my from is.
  • 5:07
    I put the colon in there and then this is the actual
  • 5:11
    directory I want.
  • 5:13
    This whole thing is from, so I'm telling it to copy
  • 5:16
    recursively from that address.
  • 5:19
    And then, to is simply to my desktop here,
  • 5:22
    and that's the path for that.
  • 5:24
    That's my command, but I have 1 last thing
  • 5:27
    I need to do because remember, we have a port on this.
  • 5:29
    This is using the same port as SSH;
  • 5:31
    it's using the same connection.
  • 5:33
    You have to use a capital P with SCP.
  • 5:37
    I used a lowercase p with SSH.
  • 5:39
    It's just the way it is.
  • 5:40
    Capital P and the port number.
  • 5:43
    And now when I enter, I get prompted for my password,
  • 5:46
    just like with SSH, and bam.
  • 5:50
    It just went ahead and downloaded everything.
  • 5:51
    So now if you go over and look on my desktop,
  • 5:54
    I have a files directory, and the 3 files that were
  • 5:57
    on my server are now copied down; not moved,
  • 6:00
    but copied down to my local machine,
  • 6:02
    and I can do what I want with them now.
  • 6:06
    It's that simple, that fast.
  • 6:08
    And then I'll just show you here.
  • 6:11
    Remember, it's the whole from-to,
  • 6:13
    so if I had something on my laptop that I wanted to send
  • 6:16
    to the remote machine, I would just change the order.
  • 6:19
    I would put my path here on my local machine.
  • 6:24
    So, it would be Desktop/files, and then I would then give
  • 6:29
    the connection information and the location on the remote
  • 6:31
    server to go to.
  • 6:33
    So, just remember, scp, from, to,
  • 6:37
    recursive if you have a directory, and put in a port number
  • 6:40
    if you need that.
  • 6:41
    And that's all it takes to access a remote server in
  • 6:44
    a very secure way.
Loading ...

Using SSH and SCP


In this video you'll see how simple it is to connect to a remote server using SSH (secure shell). We'll also look at how you can quickly and securely copy files from a remote server using the SCP command (secure copy). These are both invaluable tools when working with servers that you don't have physical access to. Note: this video was originally released April 8, 2010 on

Additional resources:
There are no resources for this video. If you believe there should be, please contact us.