Desktop login en Linux gebruikersauthenticatie

Compatible Nitrokeys

3A/C/Mini

Passkey

HSM 2

Pro 2

FIDO2

Storage 2

Start

U2F

active

active

inactive

inactive

active

inactive

inactive

active

Inleiding

This guide will walk you through the configuration of Linux to use FIDO Universal 2nd Factor, i.e. FIDO U2F with libpam-u2f and compatible Nitrokeys. You will set up your Nitrokey as a second factor for authentication. This means you will need your usual login method (likely your password) and your Nitrokey to login.

Als je in plaats daarvan je Nitrokey als alternatieve aanmeldingsmethode wilt gebruiken (wachtwoord OF Nitrokey), zie Alternatieve Authenticatiemethode na het voltooien van de hoofdhandleiding.

If you want to login to you computer using Nitrokey Pro 2, Nitrokey Storage 2 and Nitrokey Start you can visit the instructions available here.

Waarschuwing

De volgende handleiding kan u mogelijk van uw computer afsluiten. U moet zich bewust zijn van deze risico’s, want het is aanbevolen om de onderstaande instructies eerst op een tweede computer te gebruiken, of na een volledige back-up.

U kunt de toegang tot uw gegevens verliezen na het configureren van PAM-modules.

Vereisten

  • Ubuntu 24.04 with Gnome Display Manager (GDM).

Instructies

  1. Maak een backup gebruiker en geef die root rechten

    $ sudo adduser <backup_user>
    $ sudo usermod -aG sudo <backup_user>
    

    In het geval dat u U2F voor een enkele gebruiker wilt instellen, en uit uw gebruikerssessie wordt vergrendeld, kunt u nog steeds inloggen met de <backup_user>, en doorgaan met het onderhoud.

  2. Installatie libpam-u2f

    On Ubuntu 24.04 it is possible to download directly libpam-u2f from the official repos

    $ sudo apt install libpam-u2f
    

    Notitie

    • Als alternatief kunt u libpam-u2f bouwen vanuit Git.

    • Om te controleren of de bibliotheek correct is geïnstalleerd, voert u het volgende commando in:

    $ file /lib/x86_64-linux-gnu/security/pam_u2f.so
    

    De output moet iets als het volgende zijn:

    /lib/x86_64-linux-gnu/security/pam_u2f.so: \ ELF 64-bit LSB shared object, x86-64, version 1 (SYSV),\ dynamically linked, BuildID[sha1]=1d55e1b11a97be2038c6a139579f6c0d91caedb1, stripped
    
  3. Genereer het U2F config bestand

    To generate the configuration file we will use the pamu2fcfg utility. First plug your Nitrokey (if you did not already), and enter the following command:

    $ pamu2fcfg > ~/u2f_keys
    

    Once you run the command above, you will need to touch the device while it flashes. Once done, pamu2fcfg will append its output the u2f_keys file in the format:

    <username>:KeyHandle,PublicKey,flags
    

    This will look something like the following:

    nitrouser:fS6vQ9uWa0VizcczyZ/bvk5kcQJkIJOC/21/e7dXFe/fnONSL705EkeiUpZpL/3seAWL/qW4/mqb0/WtiZoP/NOLTRM4EEAg1ANLsfYgSzRd/AjsW3z8kJwgckbvwDUyB90ByR09XtBhuE41vMsEk6J+9CS0+ZuPSB0KXRG7z2yZpQLldjE/ijsdIdd8Ct2oXSiZ/zTb/t5kRafNJVkp=,Oo4U9XvIhI9r0WNnvoMwG5/pbgwYd4GMCYEinhWcsI2hKUebYj92JOxDsSa3zd2A9OB0ofXgB16FD2naev3YmLch==,es256,+presence
    

    Opmerking: deze uitvoer is niet direct gegenereerd door pamu2fcfg en bevat geen gevoelige informatie. Het is alleen bedoeld om het verwachte formaat en de lengte van de uitvoer te laten zien.

    Tip

    • The file must be named u2f_keys

    • Het wordt aanbevolen om de instructies eerst met één gebruiker te testen. Configuratie voor andere gebruikers wordt toegevoegd in hoofdstuk 7.

  4. Setting up a backup Nitrokey

    This step is optional, however it is advised to have a second Nitrokey as backup in the case of loss, theft or destruction of your primary Nitrokey.

    To set up a backup key, repeat the procedure above, and use pamu2fcfg -n like this:

    $ pamu2fcfg -n >> ~/u2f_keys
    

    This will omit the <username> field, and the output is appended to the line with your <username>, this will look something like this:

    <username>:Zx...mw,04...0a:xB...fw,es256,+presence:04...3f,es256,+presence
    
  5. Securing the config file

    Voor een betere beveiliging zullen we, nadat het configuratiebestand is gegenereerd, het gegenereerde bestand ~/u2f_keys verplaatsen naar /etc/Nitrokey/ en de toegangsrechten wijzigen met deze commando’s:

    $ sudo mkdir /etc/Nitrokey
    $ sudo mv ~/u2f_keys /etc/Nitrokey/
    $ sudo chmod 644 /etc/Nitrokey/u2f_keys
    
  6. Modificeer de Pluggable Authenticatie Module PAM

    Configureer de PAM modulebestanden onder /etc/pam.d/. Dit is een testfase - stap 8 zal de configuratie afdwingen zodra je bevestigt dat het werkt.

    In this guide we will modify the common-auth file as it handles the authentication settings which are common to all services, other options are described in PAM Modules. You can modify the file with the following command:

    $ sudo editor /etc/pam.d/common-auth
    

    Add the following line at the bottom of the file:

    #Nitrokey config
    auth    sufficient pam_u2f.so authfile=/etc/Nitrokey/u2f_keys cue [cue_prompt=Please touch the device.] prompt
    

    Tip

    • We gebruiken voldoende om te testen en wijzigen dit in vereist in stap 8.

    • Omdat we gebruik maken van Central Authentication Mapping, moeten we pam_u2f de locatie van het bestand opgeven dat we willen gebruiken met de authfile optie.

    • If you often forget to insert the key, prompt option makes pam_u2f print Insert your U2F device, then press ENTER. and give you a chance to insert the Nitrokey.

    • If you would like to be prompted to touch the Nitrokey, cue option will make pam_u2f print Please touch the device. message. You can change the message in [cue_prompt=Please touch the device.].

    Notitie

    Waarom plaatsing onderaan? PAM verwerkt modules van boven naar beneden. Door de U2F-configuratie onderaan te plaatsen, wordt de wachtwoordauthenticatie eerst gecontroleerd, waardoor een tweede-factor-workflow (wachtwoord + U2F) ontstaat.

    Voor alternatieve verificatieopties (wachtwoord OF Nitrokey) en gedetailleerde uitleg over hoe regelpositie en controlevlaggen de verificatie beïnvloeden, zie Alternatieve verificatiemethode.

    Zodra we de common-auth hebben aangepast, kunnen we het bestand opslaan en afsluiten.

    You can test the configuration by typing sudo ls in the terminal. After typing in your password you should be prompted with the message Please touch the device. and have a similar output on the terminal:

    nitrouser@nitrouser:~$ sudo ls
    [sudo] password for nitrouser:  Please touch the device.
    

    You can also test your configuration by logging out of the user session and logging back. A similar screen should be displayed once you you unplug/replug yout Nitrokey and type your password:

    img6
  7. Setting up multiple users

    Nadat je hebt bevestigd dat verificatie met behulp van je Nitrokey heeft gewerkt, kun je het U2F config bestand instellen voor de andere gebruikers op je systeem.

    Waarschuwing

    Als je niet alle gebruikers instelt in het U2F config bestand en doorgaat met het afdwingen van Nitrokey authenticatie in stap 8, zul je niet kunnen inloggen met een niet geconfigureerde gebruiker!

    To configure u2f for multiple users, pamu2fcfg takes the -u <username> option, the output can be appended to the u2f_keys file like this:

    $ sudo pamu2fcfg -u <username> >> /etc/Nitrokey/u2f_keys
    

    Om een backup Nitrokey aan deze gebruiker toe te voegen, sluit je de backup Nitrokey aan en doe je hetzelfde als bij de primaire gebruiker:

    $ sudo pamu2fcfg -n >> /etc/Nitrokey/u2f_keys
    

    Herhaal dit proces daarna voor alle gebruikers op je systeem.

  8. Enforcing Nitrokey second factor authentication

    Het is je misschien opgevallen dat authenticatie met de Nitrokey nog niet is afgedwongen. Nadat we hebben bevestigd dat authenticatie met Nitrokey werkt, kunnen we dit afdwingen door de vlag sufficient te veranderen in required.

    Waarschuwing

    Voordat je verder gaat met deze stap, moet je ervoor zorgen dat je:

    • Getest of verificatie met de Nitrokey inderdaad werkt, anders kun je de toegang tot je computer verliezen.

    • Maak een back-up Nitrokey. Als je je Nitrokey verliest of breekt, verlies je de toegang tot je computer!

    Ga voorzichtig te werk!

    Hiervoor moet je het configuratiebestand PAM bewerken:

    $ sudo editor /etc/pam.d/common-auth
    

    In de regel die je eerder onderaan het bestand hebt toegevoegd, verander je het woord sufficient in required. Het zou er nu zo uit moeten zien:

    #Nitrokey config
    auth    required pam_u2f.so authfile=/etc/Nitrokey/u2f_keys cue [cue_prompt=Please touch the device.] prompt
    

After completing the setup, it is recommended to reboot your computer and unplug/replug the Nitrokey.

Alternative Authentication Method

Als je liever je Nitrokey gebruikt als alternatief voor je wachtwoord (wachtwoord OF Nitrokey), kun je dit instellen:

Configuration Steps:

  1. Verplaats de PAM-configuratieregel naar bovenaan of /etc/pam.d/common-auth (vóór andere auth-modules)

  2. Houd de sufficient controlevlag

Dit maakt authenticatie met één van beide factoren mogelijk. Merk op dat dit minder veiligheid biedt dan authenticatie met de tweede factor.

Authenticatiemodi begrijpen

De combinatie van lijnpositie en controlevlag bepaalt je authenticatiemodus:

Authentication Modes

Position

Control Flag

Authentication Mode

Use Case

Bodem (na pam_unix)

sufficient

Second factor (testing)

Veilige testfase

Bodem (na pam_unix)

required

Tweede factor (afgedwongen)

Production security (main guide)

Top (voor pam_unix)

sufficient

Alternative factor

Convenience (password OR key)

Hoe PAM werkt:

PAM verwerkt modules opeenvolgend van boven naar beneden. De controlevlag bepaalt hoe succes of falen de algemene authenticatie beïnvloedt:

  • sufficient`: Succes voltooit authenticatie; falen wordt genegeerd als andere modules slagen

  • required: Succes is verplicht; mislukking veroorzaakt algehele authenticatiefout

Wat dit voor jou betekent:

Alternatieve authenticatie (boven + voldoende):

  • Je kunt inloggen met je wachtwoord OF alleen je Nitrokey.

  • If authentication with the Nitrokey succeeds, no password is required

  • Als de Nitrokey verificatie mislukt of wordt overgeslagen, zal het wachtwoord nog steeds werken.

  • Dit is handiger maar minder veilig dan tweede-factor-authenticatie

Security implications:

  • Een aanvaller met jouw wachtwoord kan inloggen zonder jouw Nitrokey.

  • Een aanvaller met fysieke toegang tot je Nitrokey kan inloggen zonder je wachtwoord

  • Gebruik dit alleen als gemak belangrijker is dan maximale beveiliging

Zie Controlevlaggen voor gedetailleerde uitleg over controlevlaggen en hun implicaties.

PAM modules

Er zijn verschillende PAM-modulebestanden die kunnen worden aangepast aan uw behoeften:

  • By modifying /etc/pam.d/common-auth file, you will be able to use you Nitrokey for 2nd factor authentication for graphic login and sudo.

  • If you wish to use FIDO U2F authentication solely for Gnome’s graphic login, you might prefer to modify the /etc/pam.d/gdm-password

  • U kunt ook gewoon het /etc/pam.d/sudo bestand wijzigen als u FIDO U2F wilt gebruiken wanneer u het sudo commando gebruikt.

Controlevlaggen

De controle vlag bepaalt hoe de PAM module zich gedraagt als de authenticatie slaagt of mislukt. In stap 6 gebruikten we de sufficient vlag om te testen, daarna veranderden we naar required voor handhaving.

De beschikbare controlevlaggen zijn:

  • required: The module result must be successful for authentication to continue. This is the most critical flag and can lock you out of your computer if you do not have access to the Nitrokey.

  • requisite: Vergelijkbaar met required, maar in het geval dat een specifieke module een fout teruggeeft, wordt de controle direct teruggegeven aan de toepassing, of aan de superieure PAM-stack. Deze vlag kan u ook van uw computer uitsluiten als u geen toegang tot de Nitrokey heeft.

  • sufficient: The module result is ignored if it fails. In case of success, control is directly returned to the application, or to the superior PAM stack. This means no other PAM modules will be executed. The sufficient flag is considered safe for testing purposes.

  • optional: The success or failure of this module is only important if it is the only module in the stack associated with this service+type. The optional flag is considered safe to use for testing purposes.

Waarschuwing

  • If required or requisite is set, the failure of U2F authentication will cause a failure of the overall authentication. Failure will occur when the configured Nitrokey is not plugged, lost or destroyed.

  • U zult de toegang tot uw computer verliezen als u de PAM-module verkeerd hebt geconfigureerd en de required of requisite vlaggen hebt gebruikt.

  • U verliest ook de mogelijkheid om sudo te gebruiken als u Centrale Authenticatie Mapping hebt ingesteld en de required of requisite vlaggen hebt gebruikt.

  • Je kunt ook de mogelijkheid verliezen om in te loggen met Gnome Display manager als smart card login is afgedwongen en je de required of requisite vlaggen hebt gebruikt. Zie Problemen oplossen voor meer informatie.

Problemen oplossen

Problemen met aanmelden bij gebruikersaccount met GDM

In sommige gevallen, bijvoorbeeld als je opencs-pkcs11 hebt geïnstalleerd, kan Gnome Display Manager (GDM) standaard smart card login afdwingen zodra een smart card (zoals je Nitrokey) wordt ingeplugd, zelfs als er nooit een smart card is geconfigureerd. Dit kan voorkomen dat je inlogt op je gebruikersaccount met u2f. Als je de controlevlag sufficient hebt ingesteld, koppel dan alle smartcards los en log in met je wachtwoord. Voer het volgende commando uit om het afdwingen van smartcards uit te schakelen:

$ sudo -u gdm env -u XDG_RUNTIME_DIR -u DISPLAY DCONF_PROFILE=gdm dbus-run-session gsettings set org.gnome.login-screen enable-smartcard-authentication false