How to use the command line SSH and SFTP clients

Many Unix environments have the command-line SSH and SFTP client software tools installed. This page is intended as a guide to just the basics of using these command-line tools. They have many more features than what is described here -- but these instructions should get you started.

Where would I use these?

CS account

Mac OS X home computer / laptop

Using command-line SSH

Login format:
  ssh username@host_name
In this format, username refers to your user name on the remote account you are logging into, and host_name refers to the name of the machine (usually along with doman) that you are logging into

If you leave out the username, the command will assume that you are logging into another machine with the same username as the machine you're currently on.


Using Command-Line SFTP

SFTP is Secure File Transfer Protocol. It is similar to ssh, but its primary purpose is to enable file transfers between a local machine and a remote machine, whereas the ssh (Secure Shell) protocol is for opening up a general command shell on a remote machine where you have an account.

The login format for command line sftp is exactly the same as with the ssh command, but with the "sftp" command:

  sftp username@host_name
Using the same basis of the prior example, this command would log me into with the sftp (file transfer) program as username "smith":

Local vs. Remote machines

Before you transfer files, make sure you know the difference between the local and remote machines:


Basic file transfer commands

There are more commands available than this, but the primary commands you will need are: Note here that the ls (list files) and cd (change directory) commands work exactly as you are used to them from a regular unix shell. Except when you use them as-is, you are requesting a listing or a change directory operation on the remote machine -- i.e. the machine you just sftp-ed into.

If you want to get a directory listing or change directories on the local machine, use the lls (local list files) and lcd (local change directory) commands instead.

I'm not going to describe these commands (listing and change directories) any further, as readers of this file should already be familiar with these unix commands

put and get commands

Once you have used the listing and navigation commands to put yourself in the correct directories, use get to retrieve files from the remote machine to the local account, and use put to send files from your local account to the remote account. The formats of these commands are simple, and you may use unix wildcards.


  get remote_path [local-path]  
  put local_path [remote-path]
Note that the second parameter of each command is optional -- and it will serve to specify a different name or destination directory for the transferred file. Most of the time, it's easiest to simply use put and get with a single parameter, and the destination will default to the current remote or local directory, respectively.


Other SFTP commands

To see a full list of SFTP commands and their formats, you can type help when you are logged in via sftp, and it will give you a list of available commands.

To exit the sftp login, you can use either the quit or the exit command.