Skip to content

Commit 2291072

Browse files
authored
Merge pull request #269 from NYU-RTS/mdweisner-ssh-key-1
Update 02_connecting_to_hpc.mdx
2 parents 0950138 + 371ee62 commit 2291072

1 file changed

Lines changed: 9 additions & 83 deletions

File tree

docs/hpc/12_tutorial_intro_shell_hpc/02_connecting_to_hpc.mdx

Lines changed: 9 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
Questions:
55
- How do I open a terminal?
66
- How do I connect to a remote computer?
7-
- What is an SSH key?
87

98
Objectives:
109
- Connect to a remote HPC system.
@@ -23,7 +22,7 @@ If you have ever opened the Windows Command Prompt or macOS Terminal, you have s
2322

2423
SSH clients are usually command-line tools, where you provide the remote machine address as the only required argument. If your username on the remote system differs from what you use locally, you must provide that as well. If your SSH client has a graphical front-end, such as PuTTY or MobaXterm, you will set these arguments before clicking “connect.” From the terminal, you’ll write something like ssh userName@hostname, where the argument is just like an email address: the “@” symbol is used to separate the personal ID from the address of the remote machine.
2524

26-
When logging in to a laptop, tablet, or other personal device, a username, password, or pattern are normally required to prevent unauthorized access. In these situations, the likelihood of somebody else intercepting your password is low, since logging your keystrokes requires a malicious exploit or physical access. For systems like log-1 running an SSH server, anybody on the network can log in, or try to. Since usernames are often public or easy to guess, your password is often the weakest link in the security chain. Many clusters therefore forbid password-based login, requiring instead that you generate and configure a public-private key pair with a much stronger password. Even though Torch does not require the use SSH keys to login, please consider using the instructions below to use them. It will make for quicker and more secure connections with Torch.
25+
When logging in to a laptop, tablet, or other personal device, a username, password, or pattern are normally required to prevent unauthorized access. In these situations, the likelihood of somebody else intercepting your password is low, since logging your keystrokes requires a malicious exploit or physical access. For systems like log-1 running an SSH server, anybody on the network can log in, or try to. Since usernames are often public or easy to guess, your password is often the weakest link in the security chain.
2726

2827
## Remote Connections with the NYU VPN
2928
If you are connecting from a remote location that is not on the NYU network (your home for example), you have have to set up your computer to use the NYU VPN. Once you’ve created a VPN connection, you can proceed as if you were connected to the NYU net.
@@ -94,8 +93,6 @@ It is strictly speaking not necessary to have a terminal running on your local c
9493

9594
PuTTY is available for [free download](https://www.chiark.torchnd.org.uk/~sgtatham/putty/latest.html). Download the version that is correct for your operating system and install it as you would other software on your Windows system. Once installed it will be available through the start menu or similar.
9695

97-
You can use puttygen to create ssh keys if you are using PuTTY. Please see the [puttygen page](https://www.chiark.torchnd.org.uk/~sgtatham/putty/docs.html) in the [PuTTY documentation](https://the.earth.li/~sgtatham/putty/0.83/htmldoc/) for details.
98-
9996
Running PuTTY will not initially produce a terminal but instead a window full of connection options. Putting the address of the remote system in the “Host Name (or IP Address)” box and either pressing enter or clicking the “Open” button should begin the connection process.
10097

10198
If this works you will see a terminal window open that prompts you for a username through the “login as:” prompt and then for a password. If both of these are passed correctly then you will be given access to the system and will see a message saying so within the terminal. If you need to escape the authentication process you can hold the Control (Ctrl) key and press the c key to exit and start again.
@@ -135,52 +132,7 @@ In Chrome, this can be done by navigating to this page in your settings:
135132

136133
The link above will automatically search for the Open OnDemand site data and cookies. You can then simply click on the trashcan icon to delete the site cache.
137134

138-
Once done, try navigating again to [https://ood.hpc.nyu.edu](https://ood.hpc.nyu.edu) and the site should load. For other issues please email [hpc@nyu.edu](mailto:hpc@nyu.edu).
139-
140-
## SSH keys (optional)
141-
SSH keys are an alternative method for authentication to obtain access to remote computing systems. They can also be used for authentication when transferring files or for accessing version control systems. In this section you will create a pair of SSH keys, a private key which you keep on your own computer and a public key which is placed on the remote HPC system that you will log into.
142-
143-
### Creating SSH keys on Windows
144-
We mentioned methods for creating SSH keys using some of the [Windows SSH options above](#windows).
145-
146-
### Creating SSH keys on Linux, Mac and Windows Subsystem for Linux
147-
Once you have opened a terminal check for existing SSH keys and filenames since existing SSH keys could be overwritten by the following command if the filename is the same. If you already have a key with the name given after the `-f` option you will need to change the filename to keep from losing your existing file.
148-
149-
```bash
150-
$ ls ~/.ssh/
151-
```
152-
then generate a new public-private key pair:
153-
```bash
154-
$ ssh-keygen -o -a 100 -t rsa -b 4096 -f ~/.ssh/id_Torch_rsa
155-
```
156-
- `-o` (no default): use the OpenSSH key format, rather than PEM.
157-
- `-a` (default is 16): number of rounds of passphrase derivation; increase to slow down brute force attacks.
158-
- `-t` (default is rsa): specify the “type” or cryptographic algorithm.
159-
- `-b` (default is 2048): sets the number of bits in the key.
160-
- `-f` (default is /home/user/.ssh/id_algorithm): filename to store your keys. If you already have SSH keys, make sure you specify a different name: ssh-keygen will overwrite the default key if you don’t specify!
161-
162-
When prompted, enter a strong password that you will remember. Cryptography is only as good as the weakest link, and this will be used to connect to a powerful, precious, computational resource.
163-
164-
Take a look in `~/.ssh` (use `ls ~/.ssh`). You should see the two new files: your private key (`~/.ssh/key_Torch_rsa`) and the public key (`~/.ssh/key_Torch_rsa.pub`). If a key is requested by the system administrators, the _public_ key is the one to provide.
165-
166-
:::danger
167-
Private keys are your private identity
168-
169-
A private key that is visible to anyone but you should be considered compromised, and must be destroyed. This includes having improper permissions on the directory it (or a copy) is stored in, traversing any network in the clear, attachment on unencrypted email, and even displaying the key (which is ASCII text) in your terminal window.
170-
171-
Protect this key as if it unlocks your front door. In many ways, it does.
172-
:::
173-
174-
:::tip[Further information]
175-
For more information on SSH security and some of the flags set here, an excellent resource is [Secure Secure Shell](https://blog.stribik.technology/2015/01/04/secure-secure-shell.html).
176-
:::
177-
178-
### SSH Agent for Easier Key Handling
179-
An SSH key is only as strong as the password used to unlock it, but on the other hand, typing out a complex password every time you connect to a machine is tedious and gets old very fast. This is where the SSH Agent comes in.
180-
181-
Using an SSH Agent, you can type your password for the private key once, then have the Agent remember it for some number of hours or until you log off. Unless some nefarious actor has physical access to your machine, this keeps the password safe, and removes the tedium of entering the password multiple times.
182-
183-
Just remember your password, because once it expires in the Agent, you have to type it in again.
135+
Once done, try navigating again to [https://ood.torch.hpc.nyu.edu](https://ood.hpc.nyu.edu) and the site should load. For other issues please email [hpc@nyu.edu](mailto:hpc@nyu.edu).
184136

185137
#### SSH Agents on Linux, macOS, and Windows
186138
Open your terminal application and check if an agent is running:
@@ -211,37 +163,29 @@ You could run each line of the `ssh-agent` output yourself, and achieve the same
211163
:::
212164
- Otherwise, your agent is already running: don’t mess with it.
213165

214-
Add your key to the agent, with session expiration after 8 hours:
215-
```bash
216-
[user@laptop ~]$ ssh-add -t 8h ~/.ssh/id_ed25519
217-
Enter passphrase for .ssh/id_ed25519:
218-
Identity added: .ssh/id_ed25519
219-
Lifetime set to 86400 seconds
220-
```
221-
For the duration (8 hours), whenever you use that key, the SSH Agent will provide the key on your behalf without you having to type a single keystroke.
222-
223166
#### SSH Agent on PuTTY
224167
If you are using PuTTY on Windows, download and use `pageant` as the SSH agent. See the [PuTTY documentation](./02_connecting_to_hpc.mdx#opening-a-terminal).
225168

226169

227170
## Modifying your .ssh/config file
228171
Please add the following lines to your `~/.ssh/config` file:
229172
```
230-
Host login.torch.hpc.nyu.edu dtn.torch.hpc.nyu.edu
173+
Host dtn.torch.hpc.nyu.edu
174+
User <NetID>
231175
StrictHostKeyChecking no
232176
ServerAliveInterval 60
233177
ForwardAgent yes
234178
UserKnownHostsFile /dev/null
235179
LogLevel ERROR
236180
237-
Host torch
238-
HostName localhost
239-
Port 8027
240-
ForwardX11 yes
181+
Host torch login.torch.hpc.nyu.edu
182+
Hostname login.torch.hpc.nyu.edu
183+
User <NetID>
241184
StrictHostKeyChecking no
185+
ServerAliveInterval 60
186+
ForwardAgent yes
242187
UserKnownHostsFile /dev/null
243188
LogLevel ERROR
244-
User <Your NetID>
245189
```
246190
You'll need to replace the sections above labelled `<Your NetID>` with your NetID. You can find more details about this at the [Quickstart section of Accessing HPC at NYU](https://sites.google.com/nyu.edu/nyu-hpc/accessing-hpc#h.7t97br4zzvip)
247191

@@ -253,15 +197,6 @@ SSH allows us to connect to UNIX computers remotely, and use them as if they wer
253197
ssh yourUsername@some.computer.address
254198
```
255199

256-
Let’s attempt to connect to the HPC system now:
257-
258-
If you'd like to connect without typing your password you'll need to copy your public key file to torch first:
259-
```bash
260-
scp ~/.ssh/id_Torch_rsa.pub <NetID>@login.torch.hpc.nyu.edu:/home/<NetID>
261-
```
262-
263-
You'll need to log in with your password at least once even if you plan to use SSH keys in the future because we'll need to set up your keys.
264-
265200
Once you are on the NYU WiFi or VPN you can connect with:
266201
```bash
267202
ssh <NetID>@login.torch.hpc.nyu.edu
@@ -289,15 +224,6 @@ By looking at the information after *Hostname:* and in the prompt you'll notice
289224

290225
If you logged in using PuTTY this will not apply because it does not offer a local terminal.
291226

292-
### Setting up your SSH keys (optional)
293-
294-
If you copied your SSH keys to your home directory in an earlier step, we'll guide you through setting them up for use now.
295-
1. If you do not have a directory name `.ssh` in your home directory create one now with the command: `mkdir ~/.ssh`
296-
- Remember you can list the hidden (dot) files by running the command: `ls -a`
297-
2. add your key to the list of `authorized_keys` with the command: `cat ~/id_Torch_rsa.pub >> ~/.ssh/authorized_keys`
298-
299-
That’s all! Disconnect, then try to log back into the remote: if your key and agent have been configured correctly, you should not be prompted for the password.
300-
301227
### Telling the Difference between the Local Terminal and the Remote Terminal
302228

303229
You can see that the prompt has changed after you log into a remote system. Let's take a closer look at the prompt after login: `[NetID@log-1 ~]$` (in this example) tells us that we are logged into the login node `log-1` with the identity `NetID`.

0 commit comments

Comments
 (0)