Current Students / ComputingWorking Remotely
- To execute commands interactively (at the command prompt) on a remote machine, you need a secure login shell.
- To copy files infrequently between two machines, try using scp, or possibly sftp.
- To frequently synch files between two machines, use rsync.
If you frequently work remotely, you should look into using screen.
If you need to connect to a department machine, whether from a computer in the next room or from your laptop at conference, use ssh (secure shell). Suppose you are on your laptop (named mycomp) and you want to connect to the department computer bert. On mycomp, your username is bob; on bert your username is bcw982. At a shell prompt, enter the command
bob@mycomp$ ssh firstname.lastname@example.org
In most cases you can omit some redundant information:
- if the username is omitted, ssh will use your username from the current shell, and
- if the domain name is omitted, your current domain will be used.
So if you want to connect to bert from the lab computer oscar, you need only type
bcw982@oscar:~$ ssh bert
After you connect, you will be prompted for your password; your typing will be hidden. If it's accepted, you'll see a welcome message. You can now run any command you're authorized to run on bert.
If you are connecting to a machine for the first time, you will see a different message:
bcw982@oscar:~$ ssh bert The authenticity of host 'bert (220.127.116.11)' can't be established. RSA key fingerprint is a2:77:99:fb:08:74:63:f8:52:12:0c:bd:5e:75:49:f0. Are you sure you want to continue connecting (yes/no)?
Basically, ssh is telling you that it doesn't recognize this machine, and asking you to verify its identity. Type in yes, and you get another message, along with the password prompt
Warning: Permanently added 'bert,18.104.22.168' (RSA) to the list of known hosts.
This is to inform you that ssh has stored that RSA key fingerprint in a file in your home directory, located by default at ~/.ssh/known_hosts. This is useful to know in case the OS on bert ever changes, in which case you will be unable to connect and shown a warning
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ... more information ...
To fix this, simply edit the known_hosts file, delete the line corresponding to bert, and reconnect.
If you want to use X Window GUI applications remotely, for example Matlab or Maple, you can use SSH to securely forward X network traffic from the remote machine. If you are already running an X server on the local machine (Linux or OS X), you can simply add the -X flag and then run the application as usual:
bcw982@oscar:~$ ssh -X bert
Connecting from a Windows Computer
The above steps will work on almost any Linux machine or from a shell in the Terminal application on any OS X system. On a Windows machine, you will need to install an SSH client. Three possibilities are:
- Download the PuTTY SSH client. Just run the stand-alone executable to get started.
- If you need other GNU tools on Windows (e.g. bash, less, scp, sed, grep, gcc, xmgrace, etc.) then you can install the Cygwin Linux emulator. Cygwin installation can be confusing, so make sure that the OpenSSH package is selected during package installation.
- Northwestern offers student access to Tectia, which also installs a GUI secure file transfer client.
To use X-forwarding, you may need to configure your ssh client. On PuTTy, for instance, you must select the 'Enable X11 forwarding' option as described here.
You will also need to run an X server to actually display X Window GUI applications. A good, freely-available X-server is Xming. Download and run the installer, then run the installed executable. To test your SSH client/X-server duo, log into a department computer and enter the command
$ xeyes &
You should see the eyes following your mouse cursor (If xeyes was not found, try xcalc ).
If you are interested in using a commercial X server, NUIT also has an on-site license for X-Win32, which you can use while connected to the campus network or via VPN.
If you want to copy a single file or directory securely from one machine to another, you want scp. The basic pattern is
$ scp user@host1:source-file user@host2:destination-file
or, if you want to recursively copy an entire directory,
$ scp -r user@host1:source-dir user@host2:destination-dir
If you have many files to copy, it may be easier to open a secure SFTP session. This is similar to opening a shell with SSH, except instead of a shell prompt you will get an SFTP prompt:
$ sftp bcw982@oscar Connecting to oscar... bcw982@oscar's password: sftp>
Once connected, you can use SFTP commands, including cd, ls, get, and put, to transfer files. For a full list of SFTP commands and how to use them, read
$ man sftp
rsync is a very useful and powerful file transfer utility, most commonly used to backup, mirror, or otherwise synchronize files and directories between two locations. For instance, you could edit your code on your personal computer and sync it to a cluster using the command
$ rsync -vrtplze ssh --progress --stats --delete /home/bcw982/bigproject bcw982@cluster:/home/bob/bigproject
This also illustrates that rsync has many configurable options. Read
$ man rsync
for details, and check out some more ideas here.