2380: rename ssh-access.html.textile.liquid as ssh-access-unix.html.textile.liquid
[arvados.git] / doc / user / getting_started / ssh-access-unix.html.textile.liquid
1 ---
2 layout: default
3 navsection: userguide
4 title: Accessing an Arvados VM with SSH - Unix Environments
5 ...
6
7 This document is for Unix environments (Linux, OS X, Cygwin). If you are using a Windows environment, please visit the "Accessing an Arvados VM with SSH - Windows Environments":ssh-access-windows.html page.
8
9 Arvados requires a public SSH key in order to securely log in to an Arvados VM instance, or to access an Arvados Git repository. The three sections below help you get started:
10
11 # "Getting your SSH key":#gettingkey
12 # "Adding your key to Arvados Workbench":#workbench
13 # "Using SSH to log into an Arvados VM instance":#login
14
15 h1(#gettingkey). Getting your SSH key
16
17 h3(#unix). Generate a key using ssh-keygen
18
19 Start by opening a terminal window.  Check if you have an existing public key:
20
21 notextile. <pre><code>$ <span class="userinput">ls ~/.ssh/id_rsa.pub</span></code></pre>
22
23 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 (this is your public key).  You can skip this step and proceed by "adding your key to the Arvados Workbench.":#workbench
24
25 If there is no file @~/.ssh/id_rsa.pub@, you must generate a new key.  Use @ssh-keygen@ to do this:
26
27 <notextile>
28 <pre><code>$ <span class="userinput">ssh-keygen -t rsa -C "you@example.com"</span>
29 Generating public/private rsa key pair.
30 Enter file in which to save the key (/home/example/.ssh/id_rsa):
31 Enter passphrase (empty for no passphrase):
32 Enter same passphrase again:
33 </code></pre>
34 </notextile>
35
36 * @-t@ specifies the key type (must be "rsa")
37 * @-C@ specifies a comment (to remember which account the key is associated with)
38
39 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.
40
41 Display the contents of @~/.ssh/id_rsa.pub@ (this is your public key) using @cat@ and then copy it onto the clipboard:
42
43 <notextile>
44 <pre><code>$ <span class="userinput">cat ~/.ssh/id_rsa.pub</span>
45 ssh-rsa AAAAB3NzaC1ycEDoNotUseExampleKeyDoNotUseExampleKeyDoNotUseExampleKeyDoNotUse9lmzkpBq983bQradKGT3LuKda9QOGe8MatI6wzSrJLSGhHm3hk6D8OWWUG4SneuCtKIk2bH0pgBj1G29+uzDIez90WzfCTZKbz4RcVQmPkowSSUAQDwb0ffwvRDhCgcJ1loT1wQAJzqJmljQ7xEYaCOIMqnfYE0lX7B3MSvCV6Ie2rWL33YecLp48LVtqiCOZU4XRyO8RSDFRFLVW+mjkLirwtDHZCRtORScaIEN0jw51p+T+9X5iA9QH/Mn+xlgk7fCgH+JtpBj808N/Qds2Gpff+Kb6ulUrVVfMK6L you@example.com
46 </code></pre>
47 </notextile>
48
49 Now you can set up @ssh-agent@ (next) or proceed with "adding your key to the Arvados Workbench.":#workbench
50
51 h3. Set up ssh-agent (recommended)
52
53 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:
54
55 notextile. <pre><code>$ <span class="userinput">ssh-add -l</span></code></pre>
56
57 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:
58
59 notextile. <pre><code>$ <span class="userinput">eval $(ssh-agent -s)</span></code></pre>
60
61 @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 agent process.
62
63 After running @ssh-agent@, or if @ssh-add -l@ prints "The agent has no identities", 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@:
64
65 <notextile>
66 <pre><code>$ <span class="userinput">ssh-add</span>
67 Enter passphrase for /home/example/.ssh/id_rsa:
68 Identity added: /home/example/.ssh/id_rsa (/home/example/.ssh/id_rsa)
69 </code></pre>
70 </notextile>
71
72 When everything is set up, @ssh-add -l@ should yield output that looks something like this:
73
74 <notextile>
75 <pre><code>$ <span class="userinput">ssh-add -l</span>
76 2048 eb:fa:15:f2:44:26:95:58:37:37:f4:aa:ff:ee:c2:85 you@example.com (RSA)
77 </code></pre>
78 </notextile>
79
80 You may now proceed to "adding your key to the Arvados Workbench.":#workbench
81
82 h1(#workbench). Adding your key to Arvados Workbench
83
84 h3. From the Workbench dashboard
85
86 If you have no SSH keys registered, there should be a notification asking you to provide your SSH public key.  In the Workbench top navigation menu, look for a dropdown menu with your email address in upper right corner. It will have an icon such as <span class="badge badge-alert">1</span> (the number indicates there are new notifications).  Click on this icon and a dropdown menu should appear with a message asking you to add your public key.  Paste your public key into the text area provided and click on the check button to submit the key.  You are now ready to "log into an Arvados VM":#login.
87
88 h3. Alternate way to add SSH keys
89
90 If you want to add more SSH keys, click on the user icon <span class="glyphicon glyphicon-user"></span> in the upper right corner to access the user settings menu, and click on the menu item *Manage ssh keys* to go to the Authorized keys page.
91
92 On the *Authorized keys* page, the click on the button <span class="btn btn-primary disabled">Add a new authorized key</span> in the upper right corner.
93
94 The page will reload with a new row of information.  Under the *public_key* column heading, click on the cell +New authorized key+.  This will open an editing popup as shown in this screenshot:
95
96 !{{ site.baseurl }}/images/ssh-adding-public-key.png!
97
98 Paste the public key that you copied to the cliboard in the previous section into the popup text box, then 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.
99
100 h1(#login). Using SSH to log into an Arvados VM
101
102 To see a list of virtual machines that you have access to and determine the name and login information, click on Compute %(rarr)&rarr;% Virtual machines.  Once on the *Virtual machines* page, The *hostname* columns lists the name of each available VM.  The *logins* column will have a value in the form of @["you"]@.  Your login name is the text inside the quotes.  In this guide the hostname will be _shell_ and the login will be _you_.  Replace these with your hostname and login name as appropriate.
103
104 h3. Connecting to the virtual machine
105
106 Use the following command to connect to the _shell_ VM instance as _you_.  Replace *<code>you@shell</code>* at the end of the following command with your *login* and *hostname* from Workbench:
107
108 notextile. <pre><code>$ <span class="userinput">ssh -o "ProxyCommand ssh -a -x -p2222 turnout@switchyard.{{ site.arvados_api_host }} <b>shell</b>" -A -x <b>you@shell</b></span></code></pre>
109
110 This command does several things at once. You usually cannot log in directly to virtual machines over the public Internet.  Instead, you log into a "switchyard" server and then tell the switchyard which virtual machine you want to connect to.
111
112 * @-o "ProxyCommand ..."@ configures SSH to run the specified command to create a proxy and route your connection through it.
113 * @-a@ tells SSH not to forward your ssh-agent credentials to the switchyard.
114 * @-x@ tells SSH not to forward your X session to the switchyard.
115 * @-p2222@ specifies that the switchyard is running on non-standard port 2222.
116 * <code>turnout@switchyard.{{ site.arvados_api_host }}</code> specifies the user (@turnout@) and hostname (@switchyard.{{ site.arvados_api_host }}@) of the switchyard server that will proxy our connection to the VM.
117 * *@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.
118 * After the ProxyCommand section, we repeat @-x@ to disable X session forwarding to the virtual machine.
119 * @-A@ specifies that we want to forward access to @ssh-agent@ to the VM.
120 * Finally, *<code>you@shell</code>* specifies your login name and repeats the hostname of the VM.  The username can be found in the *logins* column in the VMs Workbench page, discussed in the previous section.
121
122 You should now be able to log into the Arvados VM and "check your environment.":check-environment.html
123
124 h3. Configuration (recommended)
125
126 The command line above is cumbersome, but you can configure SSH to remember many of these settings.  Add this text to the file @.ssh/config@ in your home directory (create a new file if @.ssh/config@ doesn't exist):
127
128 <notextile>
129 <pre><code class="userinput">Host *.arvados
130   ProxyCommand ssh -a -x -p2222 turnout@switchyard.{{ site.arvados_api_host }} $SSH_PROXY_FLAGS %h
131   User <b>you</b>
132   ForwardAgent yes
133   ForwardX11 no
134 </code></pre>
135 </notextile>
136
137 This will recognize any host ending in ".arvados" and automatically apply the proxy, user and forwarding settings from the configuration file, allowing you to log in with a much simpler command:
138
139 notextile. <pre><code>$ <span class="userinput">ssh <b>shell</b>.arvados</span></code></pre>
140
141 You should now be able to log into the Arvados VM and "check your environment.":check-environment.html