Connecting to Clusters¶
Terminal Connections with SSH¶
The usual workflow for connecting to cluster login nodes is to use SSH from a terminal on your local workstation or laptop, such as
or If the username on the local workstation is the same as the NCAR systems, then that can be omitted. Similarly, to log on to Derecho, issue commands like thisssh will prompt you for a password and ask you to confirm using the two-factor authentication with DUO as described in Authenticating with Duo. See also Logging In in the Getting Started main page, which discusses compression and X11 forwarding. For various ways of streamlining the connection process, read the rest of this section.
Setting up local SSH configuration¶
On Linux and Mac systems, you can add features to your ssh connection or shorten your command line by adding to your workstation's ~/.ssh/config file. For example,
ssh <user-name>@derecho. As suggested in an NCAR HPC User Group blog post, "Streamlining two-factor authentication with ssh", you can limit the number of authentications for each cluster separately by including this in your ~/.ssh/config file. host casper derecho *.hpc.ucar.edu
ControlMaster auto
ControlPath ~/.ssh/cm-%C
ControlPersist 12h
ServerAliveInterval 120s
ServerAliveCountMax 5
~/.ssh/ for each cluster. With this enabled, you will only be required to authenticate on the first connection to each cluster, casper or derecho, from your local computer. If you are connecting to both clusters, you will need to authenticate twice for multiple connections to both. Using bao-getkey on a Mac or Linux computer, as described below, it is possible to limit that to one authentication for connecting multiple times to both clusters. OpenBao Certificates¶
bao-getkey uses OpenBao's HTTP API to request a certificate-signed SSH key for passwordless SSH within the systems managed by the High-Performance Systems Group (HSG) at NSF NCAR. This includes the Derecho and Casper Clusters.
Specifically, this script does the following, all through our OpenBao instance:
- Authenticate the user with NCAR's central authentication system
- Request a new SSH key that is signed with a trusted certificate
- Add the new private key and its certificate to your running
ssh-agent
It is a BASH script installed in the default PATH on Casper and Derecho. You may either copy it to your local Linux or Mac computer and put it in a directory in your PATH to run it locally, or you can run it from the cluster and have the key forwarded back to your local computer's agent. These procedures will be described below.
Usage¶
Options:-aRequest a certificate with necessary options for administrators. This will only work for system administrators-u <username>Specify the NCAR username to authenticate with. This is useful if your username on the NSF NCAR clusters is different than the one on your local system. Most users who are not NCAR employees will need to use this option.
Running bao-getkey from your local computer¶
Step 1: Copy the script to your computer. Log in to Derecho or Casper and find where the script is:
Then, on your local computer, copy it to a directory in yourPATH (~/bin in this example) and make it executable: Step 2: Make sure an ssh-agent is running. bao-getkey stores the new key in your ssh-agent, so it fails if no agent is running. To check, run:
Step 3: Get a key and connect.
Most macOS and Linux desktop sessions start an agent for you when you log in, and every terminal shares it. One bao-getkey authentication then works for Casper and Derecho, from any terminal, until the certificate expires. You don't need the ControlPath options in ~/.ssh/config.
Start an agent first, then get the key:
$ eval $(ssh-agent) # BASH/ZSH; for TCSH use: eval `ssh-agent -c`
$ bao-getkey -u <user-name> # -u is optional if your local username matches
$ ssh <user-name>@derecho.hpc.ucar.edu # <user-name> is optional if your local username matches
Tip
Add -A to ssh, or set ForwardAgent yes in ~/.ssh/config, if you also want to ssh from Derecho to Casper without authenticating again.
Running bao-getkey from Derecho or Casper¶
Since bao-getkey is installed on the Derecho and Casper login nodes and is already in your PATH there, this is the recommended route for anyone who can't conveniently run the script on their own machine, Windows users in particular.
The key goes into whichever ssh-agent the SSH_AUTH_SOCK environment variable points at. If you simply log in to a login node and run bao-getkey, the key ends up in an agent on that login node, which does nothing to help you log in from your own machine. To get the key into the agent on your own machine, connect with agent forwarding enabled using ssh -A, and ssh-add then adds the key back through the forwarded connection.
First make sure you have an agent running that can accept the key from bao-getkey. On local systems with BASH or ZSH, you simply run eval $(ssh-agent) first. For terminals with TCSH shells, the corresponding command is eval `ssh-agent -c`. On Windows, make sure the OpenSSH agent is running first. In PowerShell, as Administrator:
-u option here, since the script defaults to your username on the cluster, which is the one you want. Using this method, you will need to authenticate twice: once for the ssh and once for bao-getkey. Back on your own machine, ssh-add -L will show the new certificate, and logins from terminals with access to the agent will not prompt for a password until it expires. This workflow relies on your local agent accepting keys added over the forwarded connection. The OpenSSH client and agent included with Windows support this. PuTTY and Pageant may not, so PuTTY users may need to use the OpenSSH client instead.
Managing local agents¶
If your local operating system does not create an agent file for you, you may manage the agent file yourself. After the exiting back your local workstation, you can make a note of $SSH_AUTH_SOCK and use it in subsequent terminals for connections. For example, in the first terminal
You can examine the OpenBao certificate using this command string:
Thegrep string "-cert-v01" selects the OpenBao certificate, and the ssh-keygen command unpacks it into a human readable form. Of particular interest is the line that starts with "Valid:" It shows the time at which the certificate expires. Enabling agent forwarding by default and other useful configuration options¶
Adding ForwardAgent yes to your local ~/.ssh/config file will allow you to drop the -A argument for ssh on your local computer (but not on the remote systems). Without forwarding enabled, you will not be able to make an additional ssh connection on the remote system to other HSG-managed hosts without authenticating again. With forwarding enabled, you will be able to make one additional hop without authenticating, because the remote system can use your local agent through the connection. To make further hops between HSG-managed systems, you need to use agent forwarding (ssh -A) there as well.
Here are some recommended settings for your local ~/.ssh/config.
Host casper
HostName casper.hpc.ucar.edu
Host derecho
HostName derecho.hpc.ucar.edu
Host casper derecho *.hpc.ucar.edu
ForwardAgent yes
ControlMaster auto
ControlPath ~/.ssh/cm-%C
ControlPersist 12h
Host *
ServerAliveInterval 120s
ServerAliveCountMax 5
If you regularly use graphical applications with X11, consider adding this
It's simplest to add-X or -Y on the command line when you need graphics. If you do not set it in the config, ForwardX11 yes plus ForwardX11Trusted yes is the same as ssh -Y.