Ssh

Paswordless Login to Servers#

With Kerberos authentication you usually don’t need to type password when login from one Linux computer to other in the same domain.

Otherwise (e.g. if connect from your own machine) instead of typing password each time you might use SSH public key authentication. Either Linux, Windows or MacOS have SSH client installed. In Windows you might prefer PuTTY, so follow the PuTTY documentation (in brief, puttygen)

  • Generate a pair of Public/Private SSH keys on your local computer (only if not generated yet): run ssh-keygen
  • Upload public key to the server: ssh-copy-id username@sgees001.geo.vuw.ac.nz

Keep Connection Active#

To save network resources DS drops any not active connection after idle timeout (20 minutes). If you found this annoying, you might add the following lines to the top of your SSH configuration file (~/.ssh/config) :

Host *
  ServerAliveInterval 100

SSH Aliases#

SSH config file can handle abbreviations and shortcuts for preferred hosts. For example:

Host 018
  HostName sgees018.geo.vuw.ac.nz
  User doejohn

Instead of typing ssh doejohn@sgees018.geo.vuw.ac.nz you’ll need only run ssh 018

Different Environment for Different Servers#

You might find useful to set some environment variables depending on what server you’ve logged in. Just add following lines to the end of your ~/.bashrc (and edit them according to your needs):

if [ $HOSTNAME == "co501pc01.geo.vuw.ac.nz" ]; then
    # We're logged in locally to our desktop
    export PATH=$HOME/bin:$PATH
    . ~/.bash_completion
elif [ $HOSTNAME == "sgees018.geo.vuw.ac.nz" ]; then
    echo "We are on SGEES018"
    export GMT_HOME=/usr/local/gmt
else
    echo "Logged in to: $HOSTNAME"
fi

If connection is not reliable#

When you connect to the server or remote computer via SSH and start some task, you probably want to be sure that your task will not be killed because of network or power failure somewhere between your computer and server. Fortunately there are several tools which could help you to operate with your remote running programs

Generic task manipulation#

The following shell commands could be useful:

  • Ctrl+Z - active job suspend
  • jobs - jobs list
  • fg %job_number - put job to foreground (e.g.: fg %3)
  • bg %job_number - put job to background
  • disown %job_number - detach background process from terminal

Some examples of generic job managing#

Variant 1: you have started a program over ssh and realized that you need to disconnect, but keep the process running:

Ctrl+Z 
bg %1 
disown %1 

Variant 2: start the process in background with nohup:

nohup my_program 

GNU Screen#

Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells. Here are some links useful for starting:

https://gist.github.com/jctosta/af918e1618682638aa82

https://gist.github.com/fredrick/1216878

https://gist.github.com/joaopizani/2718397

https://wiki.archlinux.org/index.php/GNU_Screen

https://www.gnu.org/software/screen/manual/screen.html

For first steps you might need to remember only few screen commands:

  • screen start a new screen session
  • screen -D -R force attach to the running screen session if any available
  • screen -list get list of running screen sessions
  • screen -r session.name attach to the session by name

When in screen session:

  • Ctrl+a standard command prefix
  • Ctrl+a c create new window
  • Ctrl+a [1-9] switch between windows
  • Ctrl+a " window list
  • Ctrl+a d detach session

A typical workflow with screen:

  • Connect to the server
  • Start new screen session or attach to existing one
  • Run a program in screen session
  • Detach session (and disconnect from the server)
  • Re-attach the session to monitor the progress of running task

TMux#

Tmux is a terminal multiplexer. What is a terminal multiplexer? It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal.

https://github.com/tmux/tmux/wiki

Generally, TMux looks very similar to Screen. There are several differences, though. You might give a try to both tools and choose one which suits better.

x2Go#

X2Go is a Remote Desktop solution, which some vendors vaguely call Remote Control. This is not to be confused with Microsoft Remote Desktop Connection, which is a competing Remote Desktop solution and protocol.

With X2Go, you mainly access Linux computers. The Linux computer you are accessing is the X2Go Server. (There are ways to connect to a Windows computer as well; some of them are only available with the Linux X2Go Client.)

You can connect from a computer running Linux, Windows or Mac OS X. This computer is the X2Go Client.

SGEES Linux desktops have X2Go client installed as part of default installation. For Windows or MacOS download and install client here

x2Go troubleshooting#

Due to configuration of Linux user profile directories, starting the same program the same time on your Linux desktop and Linux server may cause collision.

Generally you should avoid of startng GUI sessions on several Linux computers simultaneously.

Most issues reported by users are caused by web browser. To prevent unexpected crash or strange behaviour either don’t start Firefox on the server, or create several separate Firefox profiles:

Profile

  • Start it as firefox -p
  • Create new profiles with some meaningful names (e.g. ‘Remote’, ‘Server’, ‘Local’, ‘My Desktop’)
  • Leave tickmark Use the selected profile without asking… empty

When you run Firefox next time, select either one or another profile depending on whether it started locally or in x2Go session.