CUCC Expedition Handbook

Key-Pair Setup

You only need to do this if you need to do bulk updates of a lot of files to the server.
- Copying files from the server does not need this.
- Only people updating or rearranging files on the server with a Bulk Update Laptop, or programmers doing troggle software development need this, e.g.

As of the server move in spring 2019 you need authorisation on the expo server to log in to get 'programmer access'. (This is not the same as logging in to the website as 'expo', which you can do with just the password.) This takes the form of an ssh key. You generate a key-pair on the machine you use for access, then send the public half to the server. Once done, all serverlogins are automatic - no passwords needed.

'ssh' is 'secure shell' and is widely used for secure access to machines and services.

What do I need to do?

You will need to run ssh-keygen/PuTTYgen on your device, email the public key to someone who already has ssh access (Wookey, Paul Fox, Philip Sargent). Once the key is installed by them you should be able to log in as 'expo' over ssh (and other software like git will also use this behind the scenes). This only needs doing once (for any machine you want access from).

Our own documentation for installing PuTTy on Windows.

Explanation of key-pairs and the ssh-keygen command.

A public key file looks like this: ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEApc9+PAMrDtWa8D8/Z..lots more like this..qmkW/cQ== wookey@khi.e. a long string of characters with 'ssh-rsa' at the start and an ID at the end (often 'user'@'machine').

Windows

On Windows 10 or later openssh comes built-in. Open a command terminal and run ssh to see if you have it installed. If so just follow the linux instructions on this page - the process is identical. You can install it if it's not there. (Microsoft setup instructions).

Windows 9 has 'WSL' (Windows Subsystem for Linux) which is basically an Ubuntu install. That's the easiest way to use ssh. Run WSL and follow the linux instuctions here.

For older Windows versions you need to use puttygen, which is part of PuTTY. You need to install that if you don't already have it.

Follow the Puttygen instructions, but the really short version is:

  • Run PuTTYgen
  • Click on 'Generate'. Follow the instructions. Don't bother adding a passphrase.
  • Type your name in the 'Key comment' field. (just so we know who's key it is)
  • Save the private key (this will create a .ppk file that you will need later)
  • Don't save the public key - instead copy all of the text from the 'Public key for pasting +into OPENSSH authorized_keys file' field, and paste that into the email. Make sure not to miss part or add newlines or otherwise mess with it.
  • Run Pageant (it will have been installed in your Start menu, otherwise find it it "C:\Program Files\PuTTY\pageant.exe"). Click the "Add Key" button. Select the .ppk file in the pop-up file list. You only need to do this once.

    Linux

    1. You need openssh-client installed - it's it extremely likely to already be installed. If not (as root/with sudo) $ sudo apt install openssh-client.
    2. You may already have a key on this machine. If you already have ~/.ssh/id_rsa.pub, then send that.
    3. If not, run $ ssh-keygen It will ask about setting a password: you can add a password for extra security, but a passwordless key is fine, and more convenient. We recommend not adding a password.
    4. That will create a file called (by default) .ssh/id_rsa.pub in your home directory. Email that file to one of the admins listed above.

    This is an example of the whole interaction where the key file has been given a different name:

    $ ssh-keygen -C "philip@muscogee-wsl"
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/philip/.ssh/id_rsa): id_rsa_wsl
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in id_rsa_wsl.
    Your public key has been saved in id_rsa_wsl.pub.
    The key fingerprint is:
    SHA256:ySs0YD5IG2ZD50+riUDHWosNq+WJdqpkDlINXh709r0 philip@muscogee-wsl
    The key's randomart image is:
    +---[RSA 2048]----+
    |  . o            |
    | ..+ .           |
    | oB+* +          |
    |.=O%.* + o       |
    |.+*o= = S .      |
    |.* o = . . .     |
    |=++.o . . E      |
    |B o    .         |
    |oo               |
    +----[SHA256]-----+
    $
    
    

    Once the nerd has told you that the public key is loaded on the server, check that it has worked by logging in to the expo server like this: $ ssh expo@expo.survex.com

    If it didn't work

    You may get this response if the public key has not been loaded properly on the server or if your laptop has not loaded the secret key properly. expo@expo.survex.com: Permission denied (publickey).

    1. Check that ssh-keygen has put both files into your Linux home .ssh folder on your laptop, if not, then move them there: $ mv id_rsa_wsl* ~/.ssh where id_rsa_wsl is the 'file in which to save the key' you specified above. (Other documentation may suggest that this file is called, e.g. 'anathema@mydevice'). But all the files int he .ssh folder must have secure access permissions, e.g. chmod 600 ~/.ssh/*

    2. Check that the ssh agent process is running and fix it if it is not (full details of how to do this give at www.ssh.com/academy/ssh/agent) $ ssh-add -l and if the process is not running, start it like this $ eval `ssh-agent`
      $ ssh-add ~/.ssh/id_rsa_wsl
      $ ssh-add -l
      ssh-add -l checks that the key is loaded and the process is running. Now try to login again with ssh expo@expo.survex.com.

    If it still doesn't work, read the online documentation, start from scratch, and do it all again but this time using all the defaults and without trying to be clever.

    MacOS

  • Erm, dunno...please fill in
  • Chromebook

  • See initial instructions in Chromebooks then follow the instructions for Linux here.
  • Android

    iOS

    Your second machine

    OK, you have an uploaded and usable key and you can ssh into the expo server. If you want to connect from another machine (e.g. your phone) it's better to make another key than try to re-use the first one. You don't need a nerd admin now, you can do this yourself. But be extremely careful to follow this exactly. If you innocently rename the files to something that appears more sensible it won't work.

    1. On your new machine, generate a key-pair. Since you are probably using a different operating system on your second machine, read the instructions above for the relevant OS. Yes you will be generating a new key. Do not re-use the key you had already.
    2. This time though, you will want to be sure that the key has a meaningful label. On Linux this means something like this: $ ssh-keygen -C "anathema.device@pulsifer" (if your name is Anathema Device and your new machine is "pulsifer"). Just click through the questions it asks accepting the defaults. It will tell you what the key files are called and where it has put them.
    3. If you accepted the defaults, the public key will be called ~/.ssh/id_rsa.pub - check that this is the case.
    4. Now copy the public key file to your first machine, the one that is already set up with a working key-pair setup with the expo server. Using email to yourself is easiest.
    5. Now upload the public key. There are 2 ways to do it:
      1. Using ssh-copy-id
      2. Using a complex collection of file transfers and file copying and appending

      Using ssh-copy-id

      On a Windows machine, Microsoft have not implemented ssh-copy-id so you need to do this instead:

      Using Filezilla and file copying

    6. Now your public key is installed for your second machine. This will enable ssh login instantly. You check that it works by logging into the expo server using ssh from your second machine: ssh expo@expo.survex.com .


    Return to Setting up a bulk update laptop