Remote Access to Linux Machines
This page describes how to connect to a remote Linux machine and run computational jobs on it from an OS X laptop. The basic connection method discussed here is SSH, described in more detail below. We consider three different methods of running jobs remotely:
- nohup: a simple and easy-to-use system for running text-based computational jobs that require no user interaction.
- screen: a more complex text-based system that allows remote text-based sessions to be disconnected and reconnected, allowing for long-running interactive jobs.
- VNC: a remote graphical desktop. See here for details.
On this page, commands that you should type at a local (on your laptop) and remote (on the Linux server) command prompt will respectively be written like:
local$ commandname -opt remote$ commandname -optIn each case, just type the text after "local$ " or "remote$ " (in this case "commandname -opt").
Local commands should be run in the Terminal program, while remote command should be run by first connecting to the remote machine with ssh, like this:
local$ ssh lagrange.mechse.illinois.edu remote$ remotecommand
SSHSSH is a text-based connection method. From a Terminal in OS X you can run
local$ ssh lagrange.mechse.illinois.eduto connect to the remote machine lagrange.mechse.illinois.edu. Some useful tricks with SSH include:
- Password-free Login. To avoid having to type a password
every time you connect, you can do this in a new Terminal window:
local$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/Users/testuser/.ssh/id_rsa): # press return here Enter passphrase (empty for no passphrase): # press return again Enter same passphrase again: # press return once more # more text here ... local$ scp .ssh/id_rsa.pub lagrange.mechse.illinois.edu: # enter your remote password local$ ssh lagrange.mechse.illinois.edu # enter your remote password again remote$ ssh-keygen -t rsa # press enter at all prompts as above remote$ cat id_rsa.pub >> .ssh/authorized_keys remote$ rm id_rsa.pub remote$ logoutNow when you connect with SSH to lagrange.mechse.illinois.edu from your laptop you should not be prompted for a password.
- Enable X11-forwarding. To enable graphical applications to
be run across a SSH connection, you can do:
local$ sudo nano /etc/ssh_config # enter your laptop passwordWithin the nano editor you can move around with the arrow keys. Add two new lines of the form:
ForwardX11 yes ForwardX11Trusted yesWhen you are done, press Control-X to exit and answer Y when asked whether you wish to save.
- Make Abbreviations for Machine Names. To avoid typing full
machine names like lagrange.mechse.illinois.edu, edit
the .ssh/config file with:
local$ nano .ssh/configThen enter text in the file like:
Host lagrange HostName lagrange.mechse.illinois.eduand press Control-X to exit (saying Y) to save. Now you can connect simply with
local$ ssh lagrange
- Run MATLAB Remotely. To run the full graphical interface
to MATLAB simply run
remote$ matlab &Alternatively, a text-based command prompt (with graphical plotting that still works) can be obtained with
remote$ matlab -nodesktop
nohupNormally any commands running will be killed when you logout of a remote machine. To stop this happening we can use the nohup command like this:
remote$ nohup <commandname> [arguments] &With MATLAB it is necessary to disable the graphical environment first with
remote$ unset DISPLAY remote$ matlab -r "<commandname>; quit" &where commandname.m is an m-file in the current directory. When using nohup, output from the command is written to the file nohup.out. To write it to another file, use
remote$ nohup <commandname> [arguments] > output.txt &to write to the file output.txt, for example.