Table of Contents

Understanding and using ssh correctly

Everything you always wanted to know about ssh, ssh keys, the passphrase and ssh agent, but were afraid to ask

At least everything you need to know in order to work efficiently, without getting bored to death

A quick introduction

Using ssh

Standard usage

  • The following will work in a Linux terminal, but can also work in a terminal on a Mac or on a Windows 10 computer
  • On Windows 10, ssh is directly available in a Windows Powershell, a Windows Terminal or the old cmd, but the most user-friendly way to use ssh is to use PuTTY

Most common options

Connecting to servers commonly used by LSCE users

LSCE servers

There are several ways to use ssh to connect to the LSCE obelixNN servers (more details about the available LSCE servers)

IPSL servers

If you want to connect to the IPSL servers (only possible with ssh keys!):

TGCC (super)computers

If you want to use the TGCC computers (e.g. irene):

IDRIS (super)computers

FIXME

Using shell aliases shortcuts to connect to the servers

If you have to use ssh regularly (with the appropriate options), you should define convenient shell aliases, or add PuTTY connection profiles on Windows

bash shell users

Define the following aliases in the ~/.bashrc configuration file of your local Linux account

# Connecting to LSCE from a computer on the LSCE network
alias obelix='ssh -A -X my_LSCE_login@obelix'

# Connecting to LSCE from outside the LSCE network
alias sobelix='ssh -A -X my_LSCE_login@ssh1.lsce.ipsl.fr -t ssh -A -X obelix'

# Connecting to ciclad @ IPSL
alias ciclad='ssh -A -X my_ciclad_login@ciclad.ipsl.jussieu.fr'

# Connnecting to irene @ TGCC
alias sirene='ssh -A -X my_LSCE_login@ssh1.lsce.ipsl.fr -t ssh -A -X my_TGCC_login@irene-ccrt.ccc.cea.fr' 

tcsh shell users

If your connection shell is tcsh instead of bash, use the appropriate alias syntax in your ~/.cshrc configuration file,
e.g. alias obelix 'ssh -A -X my_LSCE_login@obelix'

Using an X server to display graphics

A terminal can be used to display text information
e.g. the output of ls and top, the vi editor, etc…
but also to start programs that will open new (graphical) windows outside of the initial terminal
e.g. evince to display pdf files, eog to display png/jpg images, the emacs editor, ferret, etc…

If you want to use ssh to start graphical programs on a remote server, you need to:

Configuration files

ssh will store all its configuration files in a .ssh sub-directory of your home directory. The configuration files are in a text format.

You will find (some of) the following text files:

PuTTY is a convenient and user-friendly ssh client for Windows

A Terminal window will open a local Linux-like shell session on the Mac, where you can use ssh to connect to another server, or other standard Linux commands

Solving common problems

Copying files between servers/computers

Sometimes you need to copy files from one remote server (or your desktop) to the other. The files can be securely copied over ssh with the scp command

Note: you should keep the big data files were their original version is instead of duplicating them, and move the data processing (your scripts, etc…) to the server where the original files are located (e.g. the ciclad server at IPSL)

Copying files with scp

Note: the following will work in a Linux terminal, but can also work in a terminal on a Mac or on a Windows 10 computer (scp is directly available in Windows Powershell, Windows Terminal or the old cmd, but it is not the most user-friendly way to use scp on Windows)

If you have a Windows computer, it is much easier to use WinSCP for copying files

WinSCP is a convenient and user-friendly scp client for Windows

FIXME

Mirroring directories with rsync

In some cases, you may want to mirror the content of directories:

rsync is a convenient Linux command that can be used for mirroring a directory hierarchy to another location on the same computer (e.g. a removable disk), or a remote Linux machine, over ssh.

Mirroring means, in the rsync case, that we will only copy new or changed files. The first copy may take some time, but will be much faster afterwards, when only a few files have been created/changed and have to be copied. Or, if a copy is interrupted, the files already copied will not be copied a second time.

Warning! It is easy to lose files with rsync if you use the wrong syntax or options!

Mirroring no files by mistake, to a place where there are files, when using the --delete option, means that existing files or whole directory hierarchies will be deleted!

  • Be sure to understand the basic options, and use --dry-run (simulate what would be done) and -v (verbose) before performing the actual mirroring
  • Having a trailing / or not behind a directory name makes a difference!

Basic rsync syntax

Note: use man rync to get all the details and options

Local usage: rsync [OPTIONS] SRC DEST

Remote usage (i.e. the SRC and DEST directories are on different Linux machines):

         Pull: rsync [OPTIONS] [USER@]HOST:SRC... DEST
         Push: rsync [OPTIONS] SRC... [USER@]HOST:DEST
-a, --archive               archive mode; equals -rlptgoD (no -H,-A,-X)
        -r, --recursive             recurse into directories
        -l, --links                 copy symlinks as symlinks
        -p, --perms                 preserve permissions
        -t, --times                 preserve modification times
        -g, --group                 preserve group
        -o, --owner                 preserve owner (super-user only)
            --devices               preserve device files (super-user only)
            --specials              preserve special files
        -D                          same as --devices --specials


-v, --verbose               increase verbosity
-z, --compress              compress file data during the transfer
-W, --whole-file            copy files whole (w/o delta-xfer algorithm)
-C, --cvs-exclude           auto-ignore files in the same way CVS does
             RCS SCCS CVS CVS.adm RCSLOG cvslog.* tags TAGS .make.state .nse_depinfo *~ #* .#* ,*  _$*
             *$  *.old  *.bak  *.BAK *.orig *.rej .del-* *.a *.olb *.o *.obj *.so *.exe *.Z *.elc *.ln
             core .svn/ .git/ .hg/ .bzr/

--delete                delete extraneous files from dest dirs

-n, --dry-run               perform a trial run with no changes made
-c, --checksum              skip based on checksum, not mod-time & size

Examples

Using ssh keys

What are ssh keys and why use them?

ssh keys are a combination of two specific (and unique) text files, the private key file and the public key file, linked by a special kind of password called the passphrase, that can be used instead of a standard password to connect securely from one server to another server

ssh keys have to be configured properly (a few easy steps), and are very convenient because:

Generating ssh keys

Some common sense advice

Generating keys in a terminal (Linux and Mac)

If you already have a pair of ssh keys, you probably don't want to generate a new pair, unless you have been asked to (e.g. because an old encryption type like DSA has been deprecated), or you have lost one of the keys, or forgotten your passphrase. If you generate a new pair of keys, you will have to replace the old keys that you were using on all your desktops/laptops, and all the remote servers

There are several ways to generate pairs of ssh keys with ssh-keygen. The following one is the one recommended for opening an account on IPSL Mésocentre ESPRI. If you open an account on spirit, but already have a public key, just send your existing public key!

Generating or importing keys with PuTTY (Windows)

Read Converting existing ssh keys with PuTTYgen, or Creating ssh keys with PuTTYgen

Installing ssh keys

Using the keys

Using an ssh agent

An ssh agent running on your computer will securely store your passphrase and supply it to applications that use ssh on your computer to connect to remote Linux servers

Linux ssh agent

FIXME

Windows ssh agent

Mac ssh agent

Nothing to configure!

The ssh-agent process will be automatically started, if a user runs ssh or ssh-add!

Check the launchd documentation if you need more details

$ launchctl list | grep ssh
      7240	0	com.openssh.ssh-agent

It seems that, once used, the passphrase will be automatically stored in the Keychain for future sessions

More...





[ PMIP3 Wiki Home ] - [ Help! ] - [ Wiki syntax ]