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
- If you have a CS account, you have access to at least three machines
you can log into:
- shell.cs.fsu.edu
- program.cs.fsu.edu
- linprog.cs.fsu.edu
These machines all mount your home directory, so there's no need to SFTP
between them.
- You might also have an account on websrv2.cs.fsu.edu. This
would not mount your normal CS account directory, so you might
need to file transfer between this machine and others
Mac OS X home computer / laptop
- If you have a Macintosh laptop or home computer running OS X, you
cannot use the Windows SSH client unless you're running Windows emulation
or have booted into Windows
- In this case, you can use the terminal application (which
takes you into a Unix prompt on your Mac) and run the command line SSH
and SFTP programs from there
- This is useful for logging into your CS account remotely, as well as
doing file transfers between your Mac and your CS account
- To open the terminal application on a Mac:
- Go to the spotlight icon in the upper right of your desktop
- In the search box, type "terminal"
- A menu choice for the terminal application should appear. Select
this
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.
Examples
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
shell.cs.fsu.edu with the sftp (file transfer) program as username "smith":
sftp smith@shell.cs.fsu.edu
Local vs. Remote machines
Before you transfer files, make sure you know the difference between the
local and remote machines:
- The local machine is the one you started from -- i.e. the machine you
were on when you typed the "sftp" command. This might be your actual physical
computer, like a MacBook, if you're using the terminal application. This might
also be a machine you are logged into through ssh
- The remote machine is the one you just logged into via the sftp
command
Examples
Basic file transfer commands
There are more commands available than this, but the primary commands you will need
are:
- put -- copy a file from the local machine to the remote machine
- get -- copy a file from the remote machine to the local machine
- ls -- get a directory listing on the remote machine
- cd -- change your current working directory on the remote machine
- lls -- get a directory listing on the local machine
- lcd -- change your current working directory on the local machine
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.
Format:
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.
Examples
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.