Skip to content

Instantly share code, notes, and snippets.

@rmtsrc
Created February 20, 2016 13:38
Show Gist options
  • Save rmtsrc/4904527b4a3d4e07bdaa to your computer and use it in GitHub Desktop.
Save rmtsrc/4904527b4a3d4e07bdaa to your computer and use it in GitHub Desktop.
Enabling SSH U2F authentication

SSH authentication via U2F

Enabling SSH U2F authentication.

After some research online I've found a patch to the OpenSSH server that enables U2F authentication.

However there are 2 major caveats that would stop me from using this in a production environment:

  • Security - the patch for OpenSSH has not yet been accepted/merged and currently works on an older version of OpenSSH
  • Currently doesn't work on Mac OS, though maybe possible once Homebrew/legacy-homebrew#43676 is resolved

Setup

If anyones interested in trying it out here's how I set it up:

  1. Download and install:
  2. VirtualBox
  3. VirtualBox Extension Pack
  4. Ubuntu Desktop (at the time of writing I used 15.04)

First SSH client VM

  1. In VirtualBox create a new machine, but before starting it make sure that the USB Controller has been enabled for USB 2.0 or USB 3.0 and that the machine has enough RAM and video memory to operate. Enable the second network adapter and connect to your current network. Then attach the Ubuntu install ISO to it's virtual CD drive
  2. Start the VM and follow the Ubuntu install, once at the Ubuntu desktop in VirtualBox click Devices > Insert Guest Additions CD image and allow the script on the CD to run and install
  3. Following the guidance to setup Linux for use with U2F: create a: /etc/udev/rules.d/70-u2f.rules file with the following from Yubico/libu2f-host/70-u2f.rules
  4. Run: sudo apt-get update && sudo apt-get install u2f-host autoconf zlib1g-dev libu2f-host-dev libssl-dev
  5. Download openssh-6.7p1.tar.gz and extract: tar xzf openssh-6.7p1.tar.gz
  6. From Bug 2319 - [PATCH REVIEW] U2F authentication download the attached Raw Unified Diff (dated 2014-12-25 05:52 EST)
  7. Apply the patch via: patch -p1 < your-downloaded-diff-attachment.patch
  8. Build via: rm configure && autoconf -i && ./configure --with-u2f && make && sudo make install (there might be an error about 'check-config' failed, but that seems to be ok)
  9. Shutdown

Second SSH server VM

  1. Right click the VM and clone it calling it Ubuntu SSH server and reinitialise the network addresses (I used a linked clone as it's faster and uses less memory)
  2. Boot up the clone and edit the /etc/hostname and /etc/hosts files appending -2 to the hostname
  3. Add sshd user via: sudo useradd -U -r -c 'openssh daemon' -d /usr/local/sbin -s /bin/false sshd
  4. Edit /usr/local/etc/sshd_config adding:
U2FAuthentication yes
AuthenticationMethods password,u2f # or publickey,u2f
  1. Reboot the SSH server
  2. Type ifconfig making a note of it's local network IP
  3. Start the ssh daemon via: sudo /usr/local/sbin/sshd -D and it'll wait for connections

First SSH client VM

  1. Boot the first machine back up
  2. Connect your U2F key your computer, then attach it to the VM by clicking the USB icon (bottom right) and clicking Yubico Security Key
  3. Run ssh -o U2FMode=registration <ip-address-of-your-new-ssh-server> and enter your password, your U2F USB key should be flashing and it'll prompt you to press it
  4. If successful it will output your U2F public key, copy the output (e.g. ssh-u2f ... my security key)

Second SSH server VM

  1. Paste this public key into ~/.ssh/authorized_keys and save
  2. Restart the sshd server (e.g. sudo /usr/local/sbin/sshd -D)

First SSH client VM

  1. Run ssh <ip-address-of-your-new-ssh-server> and enter your password, you'll now be prompted to press your U2F key, then you should be logged in!

Seems to be a good working prototype 👍, thought it would be good to get the patch merged into OpenSSH to avoid having to build and deploy manually or if anyone knows a more stable/secure way of setting this up let me know!

@jcaesar
Copy link

jcaesar commented May 11, 2020

This seems to have support from upstream openssh as of 8.2. (Albeit the implementation/usage is a little bit different.)
https://www.openssh.com/txt/release-8.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment