You are browsing a read-only backup copy of Wikitech. The primary site can be found at wikitech.wikimedia.org

Yubikey-SSH

From Wikitech-static
Revision as of 15:41, 13 November 2015 by imported>Muehlenhoff (Initial documentation for Yubikey NEO/PIV/SSH)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Configuring the Yubikey NEO for SSH authentication in the prod cluster:

Installation

On Debian / Ubuntu:

apt-get install yubikey-personalization  yubico-piv-tool opensc

On MacOS:

brew install opensc ykpers yubico-piv-tool

Enabling CCID smartcard mode

The smartcard/CCID feature on the Yubikey NEO is disabled by default. You can change that with the following command:

ykpersonalize -m86

(See https://www.yubico.com/2012/12/yubikey-neo-composite-device/ for some more information on the parameter)

Securing physical access to the Yubikey

When accessing the NEO you need to enter a PIN to prevent access for someone who e.g. stole your Yubikey. If that PIN is entered incorrectly thrice, the Yubikey needs to be unlocked with a PUK. If that PUK is also entered incorrectly three time your Yubikey is toast, so make sure to store these in your password manager.

In addition the NEO uses a management key: It secures access when updating the feature applets running on the Yubikey and protects you from someone backdooring your NEO.

The Yubikey uses default values for PIN, PUK and management key, so we need to change all of them:

  • First the management key (24 chars hexadecimal):
key=`dd if=/dev/random bs=1 count=24 2>/dev/null | hexdump -v -e '/1 "%02X"'`
yubico-piv-tool -a set-mgm-key -n  $key
  • Now the PIN (6 digits, 123456 is the shipped default PIN):
pin=`dd if=/dev/random bs=1 count=6 2>/dev/null | hexdump -v -e '/1 "%u"'|cut -c1-6`
yubico-piv-tool -a change-pin -P 123456 -N $pin
  • Finally the PUK (8 digits, with the default 12345678)
puk=`dd if=/dev/random bs=1 count=6 2>/dev/null | hexdump -v -e '/1 "%u"'|cut -c1-8`
yubico-piv-tool -a change-puk -P 12345678 -N $puk

Key/certificate creation

First of all generate a new prvate key: (9a is a slot number, for others see the introduction of https://www.yubico.com/wp-content/uploads/2015/04/Yubico-PIV-Management-Tools_v1.0.pdf )

 yubico-piv-tool -s 9a -a generate -o public.pem

Generate a self-signed certificate:

 yubico-piv-tool -a verify-pin -P YOUR_PIN -a selfsign-certificate -s 9a -S "/CN=SSH key/" -i public.pem -o cert.pem

Import the certificate:

 yubico-piv-tool -a import-certificate -s 9a -i cert.pem

Generate an SSH pubkey

On Debian/Ubuntu and amd64:

export OPENSC="/usr/lib/x86_64-linux-gnu/pkcs11/opensc-pkcs11.so"
ssh-keygen -D $OPENSC -e

On MacOS X / Brew:

export OPENSC="/usr/local/Cellar/opensc/0.15.0/lib/opensc-pkcs11.so"
ssh-keygen -D $OPENSC -e

Accessing the key

The key is accessed via the PKCS11 interface (which OpenSSH supports):

ssh -I $OPENSC $HOST
Enter PIN for 'PIV_II (PIV Card Holder pin)':

Of course you don't need to enter the PIN all the time, ssh-agent supports PKCS11 as well. Simply run

ssh-add -s $OPENSC

to enter the key to the agent.