---
layout: default
navsection: userguide
navmenu: Getting Started
title: Accessing an Arvados VM over ssh
navorder: 2
---

h1. Accessing an Arvados Virtual Machine over ssh

Arvados requires a public @ssh@ key in order to securely log in to an Arvados VM instance, or to access an Arvados @git@ repository.

This document is divided up into three sections.

# "Getting your ssh key":#gettingkey
# "Adding your key to Arvados Workbench":#workbench
# "Using ssh to log into an Arvados VM instance":#login

h1(#gettingkey). Getting your ssh key

# "Using Unix ssh":#unix (Linux, OS X, Cygwin)
# "Using PuTTY":#windows (Windows)

h2(#unix). Unix: Using ssh-keygen

Start by opening a terminal window.  Check if you have an existing public key:

notextile. <pre><code>$ <span class="userinput">ls ~/.ssh/id_rsa.pub</span></code></pre>

If the file @id_rsa.pub@ exists, then you may use your existing key.  Copy the contents of @~/.ssh/id_rsa.pub@ onto the clipboard and proceed to "adding your key to the Arvados Workbench.":#workbench

If there is no file @~/.ssh/id_rsa.pub@, you must generate a new key.  Use @ssh-keygen@ to do this:

<notextile>
<pre><code>$ <span class="userinput">ssh-keygen -t rsa -C "you@example.com"</span>
Generating public/private rsa key pair.
Enter file in which to save the key (/home/example/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
</code></pre>
</notextile>

* @-t@ specifies the key type (must be "rsa")
* @-C@ specifies a comment (to remember which account the key is associated with)

We strongly recommend that you protect your key with a passphrase.  This means that when the key is used, you will be required to enter the passphrase.  However, unlike logging into remote system using a password, the passphrase is never sent over the network, it is only used to decrypt your private key.

If you find you are entering your passphrase frequently, you can use @ssh-agent@ to manage your credentials.  Use @ssh-add -l@ to test if you already have ssh-agent running:

notextile. <pre><code>$ <span class="userinput">ssh-add -l</span></code></pre>

If you get the error "Could not open a connection to your authentication agent" you will need to run @ssh-agent@ with the following command:

notextile. <pre><code>$ <span class="userinput">eval $(ssh-agent -s)</span></code></pre>

* @ssh-agent -s@ prints out values for environment variables SSH_AUTH_SOCK and SSH_AGENT_PID and then runs in the background.  Using "eval" on the output as shown here causes those variables to be set in the current shell environment so that subsequent calls to @ssh@ can discover how to access the @ssh-agent@ daemon.

After running @ssh-agent@, or if @ssh-add -l@ prints "The agent has no identities", then you will need to add your key using the following command.  The passphrase to decrypt the key is the same used to protect the key when it was created with @ssh-keygen@: 

<notextile>
<pre><code>$ <span class="userinput">ssh-add</span>
Enter passphrase for /home/example/.ssh/id_rsa:
Identity added: /home/example/.ssh/id_rsa (/home/example/.ssh/id_rsa)
</code></pre>
</notextile>

When everything is set up, @ssh-add -l@ should yield output that looks something like this:

<notextile>
<pre><code>$ <span class="userinput">ssh-add -l</span>
2048 eb:fa:15:f2:44:26:95:58:37:37:f4:aa:ff:ee:c2:85 you@example.com (RSA)
</code></pre>
</notextile>

Copy the contents of @~/.ssh/id_rsa.pub@ onto the clipboard and proceed to "adding your key to the Arvados Workbench":#workbench .

h2(#windows). Windows: Using PuTTY

(Note: if you are using the ssh client that comes with "Cygwin":http://cygwin.com you should follow the "Unix":#unix instructions).

"PuTTY":http://www.putty.org/ is a free (MIT-licensed) Win32 Telnet and SSH client. PuTTy includes all the tools a windows user needs to set up Private Keys and to set up and use SSH connections to your virtual machines in the Arvados Cloud. 

You can use PuTTY to create public/private keys, which are how you’ll ensure that that access to Arvados cloud is secure. You can also use PuTTY as an SSH client to access your virtual machine in an Arvados cloud and work with the Arvados Command Line Interface (CLI) client. 

You may download putty from "http://www.putty.org/":http://www.putty.org/ .

Note that you should download the installer or .zip file with all of the PuTTY tools (PuTTYtel is not required).

h3. Step 1 - Adding PuTTY to the PATH

# After downloading PuTTY and installing it, you should have a PuTTY folder in @C:\Program Files\@ or @C:\Program Files (x86)\@ (if you are using a 64 bit operating system).  If you downloaded a zip file, extract it to the location you wish to install the PuTTY applications.
# Open the Control Panel.
# Select _Advanced System Settings_, and choose _Environment Variables_.
# Under system variables, find and edit @PATH@.
# Add the following to the end of PATH (make sure to include semi colon and quotation marks):
<code>;\"C:\Program Files (x86)\PuTTY\"</code>
# Click through the OKs to close all the dialogs you’ve opened.

h3. Step 2 - Creating a Public Key

# Start PuTTYgen from the Start Menu or the folder where it was installed.
# At the bottom of the window, make sure the ‘Number of bits in a generated key’ field is set to 4096.
# Click Generate and follow the instructions to generate a key.
# Click to save the Public Key.
# Click to save the Private Key (we recommend using a strong passphrase) .
# Select the text of the Public Key and copy it to the clipboard.

h3. Step 3 - Set up Pageant

Note: Pageant is a PuTTY utility that manages your private keys so is not necessary to enter your private key passphrase every time you need to make a new ssh connection.

# Start Pageant from the Start Menu or the folder where it was installed.
# Pageant will now be running in the system tray. Click the Pageant icon to configure.
# Choose _Add Key_ and add the private key which you created in the previous step.

You are now ready to proceed to "adding your key to the Arvados Workbench":#workbench .

_Note: We recommend you do not delete the “Default” Saved Session._

h1(#workbench). Adding your key to Arvados Workbench

Open the Workbench dashboard (in this guide, this is "https://workbench.{{ site.arvados_api_host }}/":https://workbench.{{ site.arvados_api_host }}/ ) and look at the *Configuration* box.  If you do not have any ssh keys added, it will show:

bc. SSH keys   0

This indicates that you have not yet provided Arvados with your public @ssh@ key.  Click on "SSH keys" or use the menu item _Access %(rarr)&rarr;% Keys_ to add an authorized ssh key to your account.

Click on the button <span class="btn btn-primary disabled">Add a new authorized key</span>.

This will reload the page, and should now show a row of information.  Under the *public_key* column heading, click on the cell _none_ .  This should open up an editing popup as shown in this screenshot:

!{{ site.baseurl }}/images/ssh-adding-public-key.png!

Paste the public key that you copied to the clipboard in the previous section into the popup text box and click on the check mark to save it.  This should refresh the page with the public key that you just added now listed under the *public_key* column.  You are now ready to "log into an Arvados VM":#login.

h1(#login). Using ssh to log into an Arvados VM

To determine the name and login information of the VM instance that you will connect to, go to the Arvados workbench and click on "Virtual machines" under *Configuration* or use the menu item _Access %(rarr)&rarr;% VMs_ to see a list of virtual machines that you have access to.  Make a note of the values in the *hostname* and *logins* columns.  In this guide the hostname will be _shell_ and the login will be _you_.  Replace these with your hostname and login as appropriate.

This section consists of two sets of instructions, depending on whether you will be logging in using a "Unix":#unixvm (Linux, OS X, Cygwin) or "Windows":#windowsvm client.

h2. Logging in using command line ssh (Unix)

h3(#unixvm). Connecting to the VM

Use the following command to connect to the "shell" VM instance as "you":

notextile. <pre><code>$ <span class="userinput">ssh -o "ProxyCommand ssh -a -x -p2222 turnout@switchyard.{{ site.arvados_api_host }} shell" -A -x you@shell</span></code></pre>

There are several things going on here:

The VMs typically have addresses that are not globally routable, so you cannot log in directly.  Instead, you log into a "switchyard" server and then tell the switchyard which VM you want to connect to.

* @-o "ProxyCommand ..."@ option instructs ssh to run the specified command and then tunnel your ssh connection over the proxy.
* @-a@ tells ssh not to forward your ssh-agent credentials to the switchyard
* @-x@ tells ssh not to forward your X session to the switchyard
* @-p2222@ specifies that the switchyard is running on non-standard port 2222
* <code>turnout@switchyard.{{ site.arvados_api_host }}</code> specifies the user (@turnout@) and hostname (@switchyard.{{ site.arvados_api_host }}@) of the switchboard server that will proxy our connection to the VM.
* @shell@ is the name of the VM that we want to connect to.  This is sent to the switchyard server as if it were an ssh command, and the switchyard server connects to the VM on our behalf.
* After the ProxyCommand section, the @-x@ must be repeated because it applies to the connection to VM instead of the switchyard.
* @-A@ specifies that we want to forward access to @ssh-agent@ to the VM.
* Finally, <code>you@shell</code> specifies your username and repeats the hostname of the VM.  The username can be found in the *logins* column in the VMs Workbench page, discussed above.

You should now be able to log into the Arvados VM and "check your environment.":check-environment.html

h3. Configuration (optional)

Since the above command line is cumbersome, it can be greatly simplfied by adding the following section your @~/.ssh/config@ file:

<notextile>
<pre><code class="userinput">Host *.qr1hi
  ProxyCommand ssh -a -x -p2222 turnout@switchyard.{{ site.arvados_api_host }} $SSH_PROXY_FLAGS %h
  User you
  ForwardAgent yes
  ForwardX11 no
</code></pre>
</notextile>

This will recognize any host ending in ".qr1hi" and automatically apply the proxy, user and forwarding settings discussed previously.  For example:

notextile. <pre><code>$ <span class="userinput">ssh shell.qr1hi</span></code></pre>

h2(#windowsvm). Logging in using PuTTY (Windows)

h3. Initial configuration

# Open PuTTY from the Start Menu.
# On the Session screen set the Host Name (or IP address) to “shell”.
# On the Session screen set the Port to “22”.
# On the Connection %(rarr)&rarr;% Data screen set the Auto-login username to the username listed in the *logins* column on the Arvados Workbench _Access %(rarr)&rarr;% VMs_ page.
# On the Connection %(rarr)&rarr;% Proxy screen set the Proxy Type to “Local”.
# On the Connection %(rarr)&rarr;% Proxy screen in the “Telnet command, or local proxy command” box enter:
<code>plink -P 2222 turnout@switchyard.qr1hi.arvadosapi.com %host</code>
Make sure there is no newline at the end of the text entry.
# Return to the Session screen. In the Saved Sessions box, enter a name for this configuration and hit Save. 

h3. Connecting to the VM

# Open PuTTY 
# Click on the Saved Session name you created in the previous section.
# Click Load to load those saved session settings.
# Click Open and that will open the SSH window at the command prompt. You will now be logged in to your virtual machine.

You should now be able to log into the Arvados VM and "check your environment.":check-environment.html
