Skip to content
This repository was archived by the owner on Aug 14, 2024. It is now read-only.

Commit bc2ce75

Browse files
authored
Merge pull request #39 from bkmgit/add-ssh-key-instructions
Add ssh key instructions
2 parents 75ab95f + 7cedea4 commit bc2ce75

File tree

1 file changed

+116
-12
lines changed

1 file changed

+116
-12
lines changed

_episodes/01-connecting.md

+116-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
---
22
title: "Connecting to the remote HPC system"
3-
teaching: 20
3+
teaching: 25
44
exercises: 10
55
questions:
66
- How do I open a terminal?
77
- How do I connect to a remote computer?
8+
- What is an SSH key?
89
objectives:
910
- Connect to a remote HPC system.
1011
keypoints:
11-
- To connect to a remote HPC system using SSH,
12+
- To connect to a remote HPC system using SSH and a password,
1213
run `ssh [email protected]`.
14+
- To connect to a remote HPC system using SSH and an SSH key,
15+
run `ssh -i ~/.ssh/key_for_remote_computer [email protected]`.
1316
---
1417

1518
## Opening a Terminal
@@ -34,10 +37,6 @@ then a quick search on the Internet for "how to open a terminal window in" with
3437
your particular Linux flavour appended to the end should quickly give you the
3538
directions you need.
3639

37-
A very popular version of Linux is Ubuntu. There are many ways to open a
38-
terminal window in Ubuntu but a very fast way is to use the terminal shortcut
39-
key sequence: Ctrl+Alt+T.
40-
4140
### Mac
4241

4342
Macs have had a terminal built in since the first version of OS X since it is
@@ -104,10 +103,10 @@ PuTTY is likely the oldest, most well-known, and widely used software solution
104103
to take this approach.
105104

106105
PuTTY is available for free download from
107-
[www.putty.org](http://www.putty.org/). Download the version that is correct
108-
for your operating system and install it as you would other software on your
109-
Windows system. Once installed it will be available through the start menu or
110-
similar.
106+
[https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html](https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html).
107+
Download the version that is correct for your operating system and install it
108+
as you would other software on your Windows system. Once installed it will be
109+
available through the start menu or similar.
111110

112111
Running PuTTY will not initially produce a terminal but instead a window full
113112
of connection options. Putting the address of the remote system in the "Host
@@ -129,6 +128,94 @@ For those logging in with PuTTY it would likely be best to cover the terminal
129128
basics already mentioned above before moving on to navigating the remote
130129
system.
131130

131+
## Creating an SSH key
132+
133+
SSH keys are an alternative method for authentication to obtain access to
134+
remote computing systems. They can also be used for authentication when
135+
transferring files or for accessing version control systems. In this section
136+
you will create a pair of SSH keys, a private key which you keep on your
137+
own computer and a public key which is placed on the remote HPC system
138+
that you will log in to.
139+
140+
### Linux, Mac and Windows Subsystem for Linux
141+
142+
Once you have opened a terminal check for existing SSH keys and filenames
143+
since existing SSH keys are overwritten,
144+
```
145+
$ ls ~/.ssh/
146+
```
147+
{: .language-bash}
148+
149+
then generate a new public-private key pair,
150+
```
151+
$ ssh-keygen -t ed25519 -a 100 -f ~/.ssh/id_{{ site.workshop_host }}_ed25519
152+
```
153+
{: .language-bash}
154+
155+
- `-o` (no default): use the OpenSSH key format,
156+
rather than PEM.
157+
- `-a` (default is 16): number of rounds of passphrase derivation;
158+
increase to slow down brute force attacks.
159+
- `-t` (default is [rsa](https://en.wikipedia.org/wiki/RSA_(cryptosystem))):
160+
specify the "type" or cryptographic algorithm.
161+
[ed25519](https://en.wikipedia.org/wiki/EdDSA)
162+
is faster and shorter than RSA for comparable strength.
163+
- `-f` (default is /home/user/.ssh/id_algorithm): filename to store your keys.
164+
If you already have SSH keys, make sure you specify a different name:
165+
`ssh-keygen` will overwrite the default key if you don't specify!
166+
167+
If ed25519 is not available, use the older (but strong and trusted)
168+
[RSA](https://en.wikipedia.org/wiki/RSA_(cryptosystem)) cryptography:
169+
170+
```
171+
$ ls ~/.ssh/
172+
$ ssh-keygen -o -a 100 -t rsa -b 4096 -f ~/.ssh/id_{{ site.workshop_host }}_rsa
173+
```
174+
{: .language-bash}
175+
176+
The flag `-b` sets the number of bits in the key.
177+
The default is 2048. EdDSA uses a fixed key length,
178+
so this flag would have no effect.
179+
180+
When prompted, enter a strong password that you will remember.
181+
Cryptography is only as good as the weakest link, and this will be
182+
used to connect to a powerful, precious, computational resource.
183+
184+
Take a look in `~/.ssh` (use `ls ~/.ssh`). You should see the two
185+
new files: your private key (`~/.ssh/key_{{ site.workshop_host }}_ed25519`
186+
or `~/.ssh/key_{{ site.workshop_host }}_rsa`) and
187+
the public key (`~/.ssh/key_{{ site.workshop_host }}_ed25519.pub` or
188+
`~/.ssh/key_{{ site.workshop_host }}_rsa.pub`). If a key is
189+
requested by the system administrators, the *public* key is the one
190+
to provide.
191+
192+
> ##### Private keys are your private identity
193+
>
194+
> A private key that is visible to anyone but you should be considered compromised,
195+
> and must be destroyed. This includes having improper permissions on the directory
196+
> it (or a copy) is stored in, traversing any network in the clear, attachment on
197+
> unencrypted email, and even displaying the key (which is ASCII text) in your
198+
> terminal window.
199+
>
200+
> Protect this key as if it unlocks your front door. In many ways, it does.
201+
{: .caution}
202+
203+
> #### Further information
204+
>
205+
> For more information on SSH security and some of the
206+
> flags set here, an excellent resource is
207+
> [Secure Secure Shell](https://stribika.github.io/2015/01/04/secure-secure-shell.html).
208+
{: .callout}
209+
210+
211+
### Windows
212+
213+
On Windows you can use
214+
- puttygen, see the Putty
215+
[documentation](https://www.chiark.greenend.org.uk/~sgtatham/putty/docs.html)
216+
- MobaKeyGen, see the MoabXterm
217+
[documentation](https://mobaxterm.mobatek.net/documentation.html)
218+
132219
## Logging onto the system
133220

134221
With all of this in mind, let's connect to a remote HPC system. In this
@@ -140,14 +227,31 @@ example computer, we will use SSH (if you are using PuTTY, see above).
140227

141228
SSH allows us to connect to UNIX computers remotely, and use them as if they
142229
were our own. The general syntax of the connection command follows the format
143-
`ssh [email protected]` Let's attempt to connect to the HPC
144-
system now:
230+
`ssh -i ~/.ssh/key_for_remote_computer [email protected]`
231+
when using SSH keys and `ssh [email protected]` if only
232+
password access is available. Let's attempt to connect to the HPC system
233+
now:
234+
235+
```
236+
ssh -i ~/.ssh/key_{{ site.workshop_host }}_ed25519 yourUsername@{{ site.workshop_host_login }}
237+
```
238+
{: .language-bash}
239+
240+
or
241+
242+
```
243+
ssh -i ~/.ssh/key_{{ site.workshop_host }}_rsa yourUsername@{{ site.workshop_host_login }}
244+
```
245+
{: .language-bash}
246+
247+
or if SSH keys have not been enabled
145248

146249
```
147250
ssh yourUsername@{{ site.workshop_host_login }}
148251
```
149252
{: .language-bash}
150253

254+
151255
```
152256
{% include /snippets/01/login_output.{{ site.workshop_host_id }} %}
153257
```

0 commit comments

Comments
 (0)