Getting Down with ...

by ...

Lesson 6: Remote connecting with ssh, scp and sftp

ssh

The ssh program provides secure remote-login from the Unix command-line interface (CLI) over an unsecured network. The ssh command syntax looks like this:

$ ssh [user@]host

Where host is the name of the remote network computer to which you want to login, and user is the name of the user on that host. [user@] is written within square brackets ([]) since if the user name on the machine from which the connection is being made is the same as the user name on the host it can be omitted.

scp

The scp program provides a secure means of transfering files between networked computers using the Unix command-line interface (CLI) over an unsecured network.

The scp command syntax looks like this:

$ scp sourcefile [user@]host:path/targetfile 

sftp

sftp is a subsystem of ssh intended to replace the older, File Transfer Protocol (FTP) which is not secure and is increasingly not supported for this reason.

Using sftp to transfer files

Successfully connecting to a remote machine with:

$ sftp [user@]host

will give you a prompt like this:

sftp>

From here, you can use the following commands to list files on both the local and remove machines move files back and forth between them:

lpwd
Display the path of the current working directory on the local machine.
pwd
Display the path of the current working directory on the remote machine.
lcd path
Change the current working directory on local machine to path.
cd path
Change the current working directory on remote machine to path.
lls
Display the contents of the current working directory on the local machine.
ls
Display the contents of the current working directory on the remote machine.
get [remote path]/filename [local path]
Copy filename from [remote path] (defaults to current working directory if not included) on the remote to [local path] (defaults to current working directory if not included) on the local machine.
mget [remote path]/filename matching pattern [local path]
Copy all files matching filename matching pattern from [remote path] (defaults to current working directory if not included) on the remote machine to [local path] (defaults to current working directory if not included) on the local machine.
put [local path]/local filename [remote path]
Copy local filename located at [local path] (defaults to current working directory if not included) to [remote path] (defaults to current working directory if not included) on the remote machine.
mput [local path]/[local filename matching pattern] [remote path]
Copy all files matching [local filename matching pattern] located at [local path]] to [remote path] on the remote machine.

Exercises:

Note: The following exercises assume availability of a remote unix host to which you can login.

  1. Use the ssh command to login to a remote host. Write down the exact command you used to do this.
  2. Use the scp command to copy an image file from your local machine to the same remote host you logged into in the previous exercise. Then use ssh to log back into the remote host and use the ls to confirm that your image file has been copied there.