The default PIN code is 123456. The default PUK code is 12345678.
The default 3DES management key (9B) is 010203040506070801020304050607080102030405060708.
Ubuntu
$ sudo apt-add-repository ppa:yubico/stable
$ sudo apt update
$ sudo apt install yubikey-manager
MacOS
$ brew install ykman
For more ways to install ykman, please refer to official documentation here.
- Change YubiKey device PIN, PUK and Management Key if they're still using default ones. (Optional, but highly recommended for security reasons)
$ ykman piv change-pin
Enter current PIN first, if it's the default, enter 123456, then enter the new PIN twice to save it.
$ ykman piv change-puk
Enter current PUK first, if it's the default, enter 12345678, then enter the new PUK twice to save it.
$ ykman piv change-management-key
Enter current Management Key first, if it's the default, enter 010203040506070801020304050607080102030405060708, then enter the new Management Key twice to save it.
For more information about how are they being used, please refer to official documentation here.
- Generate a key in slot 9a:
$ ykman piv generate-key 9a public.pem
For full slots reference, please refer to official documentation here.
- Create a self-signed certificate for that key:
$ ykman piv generate-certificate -s "/CN=SSH-key/" 9a public.pem
If there is no error showing up, the generated certificate has already been imported to the YubiKey device automatically.
No need to manually import certificate back like the yubico-piv-tool is doing here.
- Find out where OpenSC has installed the pkcs11 module.
- For OS X with binary installation this is typically in
/Library/OpenSC/lib/. Homebrew users can useexport OPENSC_LIBS=$(brew --prefix opensc)/lib. - For a Debian based system this is typically in
/usr/lib/x86_64-linux-gnu/. After this we’ll call this location$OPENSC_LIBS.
- Export the public key in correct format for ssh and once you got it, add it to authorized_keys on the target system.
$ ssh-keygen -D $OPENSC_LIBS/opensc-pkcs11.so -e
- Authenticate to the target system using the new key:
$ ssh -I $OPENSC_LIBS/opensc-pkcs11.so user@remote.example.com
- Setup YubiKey to work with ssh-agent:
$ ssh-add -s $OPENSC_LIBS/opensc-pkcs11.so
Note:
Since MacOS Sierra 10.12.4,
agent refused operationerror maybe showing for pkcs11 module. This is becauseopensc-pkcs11.sois not installed in a "whitelisted" location for the new version of OpenSSH, e.g./usr/local/opt/opensc/lib. The easiest way to fix this is to copy/moveopensc-pkcs11.soto a "whitelisted" location, e.g./usr/local/lib. Symbolic link will not work in this scenario,opensc-pkcs11.sohas to be copied/moved into a "whitelisted" location. The issue is discussed here.
To confirm that the ssh-agent correctly finds that key and getting the public key in correct format:
$ ssh-add -L
- Alternatively, selectively add the PKCS11Provider to
~/.ssh/config:
Host remote.example.com
PKCS11Provider /usr/local/lib/opensc-pkcs11.so
Port 22
User user
Please, run the ssh-agent in debug mode to see what is the problem in your case:
ssh-agent -d -a ~/.agent.socket
and in different terminal try to add the card:
SSH_AUTH_SOCK=~/.agent.socket ssh-add -s /usr/local/lib/opensc-pkcs11.so