SSH, SFTP, SCP

SSH

Almost every computer now includes the ssh command which can be used on the commmand line to log into a remote computer that supports. (You can even get ssh clients for tables and smart phones, though they are hard to use without a real keyboard.)

For example, to connect to the computer csfac5.hws.edu, you would just use the command

    ssh username@csfac5.hws.edu

where username should be replaced with your user name on your math/cs Linux account. Instead of csfac5, you can use any of the computer names csfac0, csfac1, csfac2, csfac3, csfac4, csfac5, csfac6, or csfac7.

This will work only if you are properly connected to the campus "Private" wireless network or to campus Ethernet. You should be able to connect to math.hws.edu from anywhere in the world, including from campus, using

     ssh username@math.hws.edu

However, not all programs that are installed in the lab are available on math.hws.edu. Please use one of the csfac computers if you are on campus.

(The lab machines cslab0.hws.edu, cslab1.hws.edu, ..., cslab11.hws.edu can also be used for ssh, but those computers are more likely to be turned off or restarted without warning, which isn't nice when you are working on the computer remotely.)

An ssh client logs you into a command line interface. If you want to edit files on the remote computer, you might think about learning the vim editor, which works on the command line. Alternatively, you can use SFTP to copy files back and forth between your local computer and the romote computer, and do the editing on your local machine.

You cannot use GUI program such as text editors through a normal ssh connection. For Windows, you might look at the free version of MobaXTerm, a single Windows application that integrates ssh, sftp, and other Linux utilities. Although it is a commercial program, there is a free "Home Edition." You can download the "Portable edition," which can run as an application from your home directory or even from a USB stick. You can create an "ssh session" in MobaXterm to connect to a computer, and it automatically supports GUI programs. However, note that running GUI programs remotely over an ssh connection might be very slow. MobaXTerm also supports "sftp sessions" that allow you to upload and download files and even edit remote files using a built-in text editor. In fact, when you open an ssh session, you get an sftp session automatically.

It is possible to run Linux GUI programs through ssh on Mac OS, such as by installing the XQuartz application. With XQuartz installed, you can use ssh -X to connect to one of our lab computers and run GUI programs remotely. For example,

    ssh  -X  username@csfac5.hws.edu

SCP

If your computer supports ssh, it should also support scp, a command for copying files from one computer to another. For example, to copy a file from your computer to your home directory in your math/cs Linux account, use a command such as

     scp  filename.ext  username@csfac5.hws.edu:

You need to be working in the directory that contains the file. The ":" at the end is very important, since it is what tells the command that you are copying to a remote computer. If you leave it out, you will simply get a copy of the file on your own computer, named username@csfac.hws.edu. You can copy to a csfac computer only if you are on campus. From anywhere in the world, you can use

     scp  filename.ext  username@math.hws.edu:

You can copy an entire directory, but you have to add the option "-r" to the command:

     scp  -r  directoryname  username@csfac5.hws.edu:

These commands will copy the file or directory into your home directory. You can specify a different location for the copy by adding a path to the destination. For example, to copy the file onto your Linux Desktop,

     scp  filename.ext  username@csfac5.hws.edu:Desktop

Note that if a file of the same name already exists on the remote computer, it will simply be deleted and replaced by the file that you are copying. So, be careful.

SFTP

Although scp is useful, it's not as convenient as it could be, especially if you don't know the names of files on the remote computer. An alternative for transferring files between computers is sftp. You can use sftp to connect to math.hws.edu or to any of the csfac computers. A command-line sftp session can be started with a command such as

      sftp username@math.hws.edu

You might be asked to confirm that you want to connect; answer by typing the complete word yes and pressing return. After giving your Linux password, you will be able to use the commands put <filenam> and get <filenam> to transfer individual files between the local computer and the remote computer. Use put -r <dirnam> and get -r <dirnam> to transfer entire directories. The ls command will list files in the current directory on the remote computer, and the cd command can be used to change directories on the remote computer. To list files and change directories on the local computer, use the commands lls and lcd. Use exit to end the sftp session. The pwd command prints the name of the current directory on the remote computer, and lpwd does the same for the local computer. (On Linux or Mac OS, see the man page for sftp for more information.)

Note that if you are connected to the HWS network, you can connect to one of the computers csfac0@hws.edu, csfac1@hws.edu, ..., csfac7@hws.edu instead of to math.hws.edu. You should be able to connect to math.hws.edu from anywhere.


Really, command-line sftp is fairly fast and easy to use! However, you might prefer a GUI interface for SFTP. Various GUI programs are available for file transfer using SFTP. A GUI interface to SFTP will usually let you see files on your computer alongside files on the remote computer, and you will be able to easily copy files in either direction, such as by dragging. You can search for GUI SFTP programs, but do try out the command line first!

Some text editors make it possible to open a file on a remote computer for editing. For example, BBEdit for Mac has an "Open from FTP/SFTP command" that makes this very easy. And Komodo Edit has an "Open"/"Remote File" command (but it requires adding a server configuration). Usually, all you need to know is the computer that you want to connect to, which will be math.hws.edu or one of the csfac computers, and your Linux username and password.