DEV Community

Set up Yubikey for Passwordless Sudo Authentication

bashbunni on January 24, 2022

Passwordless auth with Yubico 5 NFC on Ubuntu Resources Using U2F for passwordless sudo Prerequisites sudo apt-ge...
Collapse
 
clarksoncj profile image
Chris Clarkson •

Thanks for this, A great walkthough.

For those like me who forget that the Yubikey is set up for this kind of thing you can add a cue to /etc/pam.d/sudo to give you a message, instead of just the paused prompt.

auth sufficient pam_u2f.so cue [cue_prompt="Tap the Yubikey to Sudo"]

Developer Reference has some other good options to add if you need them too

Collapse
 
bashbunni profile image
bashbunni •

Ah I never thought of this. Thank you for sharing!!

Collapse
 
savaged profile image
David Savage •

Thank you for this post. I've implemented it and feel more secure ;)
However, there is one gap, namely how to do the same for su. I tried the same process for su but got this message: su: Authentication service cannot retrieve authentication info. Any ideas?

Collapse
 
waylonwalker profile image
Waylon Walker •

2FA sudo command, so cool

Collapse
 
andreanidouglas profile image
Douglas R Andreani •

this is awesome, thanks

Collapse
 
bashbunni profile image
bashbunni •

I'm so glad it's helpful for you!

Collapse
 
ytvwld profile image
Niklas •

This is great.

Also, it works pretty similar for polkit, just that it's /etc/pam.d/polkit-1.

Collapse
 
pusher018 profile image
pusher018 •

Nice tutorial, I was doing it as 2FA but I would love to switch to passwordless if we could require the PIN of the yubikey before touching.

Also, can I do it on a remote server connected in ssh or it's only for key connected on the local machine?

Collapse
 
christianfosli profile image
Christian Fosli •

I came here wondering the same thing. Found a solution, sharing it here for reference even though it's a year later 😄.

I found out pam_u2f.so has a pinverification=int option for this.
Replacing auth sufficient pam_u2f.so with auth sufficient pam_u2f.so pinverification=1 in /etc/pam.d/sudo seems to do the trick!

Collapse
 
dffvb profile image
dffvb •

Will this work over SSH?

Collapse
 
ytvwld profile image
Niklas •

sadly, no. But pam_yubico.so should work.