Prihlasovanie do počítača a overovanie používateľov systému Linux¶
Compatible Nitrokeys |
|||||||
|---|---|---|---|---|---|---|---|
✓ active |
✓ active |
⨯ inactive |
⨯ inactive |
✓ active |
⨯ inactive |
⨯ inactive |
✓ active |
Úvod¶
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.
If you want to use your Nitrokey as an alternative login method instead (password OR Nitrokey), see Alternative Authentication Method after completing the main guide.
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.
Varovanie
Nasledujúci návod vás môže potenciálne zablokovať v počítači. Mali by ste si byť vedomí týchto rizík, pretože sa odporúča použiť nižšie uvedené pokyny najprv na sekundárnom počítači alebo po úplnom zálohovaní.
Po konfigurácii modulov PAM môžete stratiť prístup k svojim údajom.
Požiadavky¶
Ubuntu 24.04 with Gnome Display Manager (GDM).
Pokyny¶
Vytvorte záložného používateľa a dajte mu práva root
$ sudo adduser <backup_user> $ sudo usermod -aG sudo <backup_user>
V prípade, že uprednostňujete nastavenie U2F pre jedného používateľa a ste uzamknutí v relácii používateľa, stále sa budete môcť prihlásiť pomocou
<backup_user>a pokračovať v údržbe.Inštalácia
libpam-u2fOn Ubuntu 24.04 it is possible to download directly
libpam-u2ffrom the official repos$ sudo apt install libpam-u2f
Poznámka
Prípadne môžete zostaviť
libpam-u2fz Git.Ak chcete overiť, či je knižnica správne nainštalovaná, zadajte nasledujúci príkaz:
$ file /lib/x86_64-linux-gnu/security/pam_u2f.so
Výstup by mal byť podobný nasledujúcemu:
/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
Generovanie konfiguračného súboru U2F
To generate the configuration file we will use the
pamu2fcfgutility. 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,
pamu2fcfgwill append its output theu2f_keysfile 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
Note, this output was not generated directly by
pamu2fcfgand contains no sensitive information. It is purely meant to show the expected format and length of the output.Tip
The file must be named
u2f_keysIt is recommended to first test the instructions with a single user. Other users configuration will be added it section 7.
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 -nlike 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
Securing the config file
For better security, after the config file was generated, we will move the generated file
~/u2f_keysto/etc/Nitrokey/and change the access permissions using these commands:$ sudo mkdir /etc/Nitrokey $ sudo mv ~/u2f_keys /etc/Nitrokey/ $ sudo chmod 644 /etc/Nitrokey/u2f_keys
Modifikácia zásuvného modulu overovania
PAMConfigure the PAM module files under
/etc/pam.d/. This is a testing phase - step 8 will enforce the configuration once you confirm it works.In this guide we will modify the
common-authfile 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 are using sufficient for testing and will change to required in Step 8.
Keďže používame centrálne autentifikačné mapovanie, musíme povedať
pam_u2fumiestnenie súboru, ktorý sa má použiť pomocou možnostiauthfile.If you often forget to insert the key,
promptoption makespam_u2fprintInsert 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,
cueoption will makepam_u2fprintPlease touch the device.message. You can change the message in[cue_prompt=Please touch the device.].
Poznámka
Why bottom placement? PAM processes modules from top to bottom. Placing the U2F configuration at the bottom ensures password authentication is checked first, creating a second-factor workflow (password + U2F).
For alternative authentication options (password OR Nitrokey) and detailed explanations of how line position and control flags affect authentication, see Alternative Authentication Method.
Po úprave
common-authmôžeme súbor uložiť a ukončiť.You can test the configuration by typing
sudo lsin the terminal. After typing in your password you should be prompted with the messagePlease 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:
Setting up multiple users
After confirming that authentication using your Nitrokey did work, you can set up the U2F config file for the other users on your system.
Varovanie
Should you not set up all users in the U2F config file and continue with enforcing Nitrokey authentication in step 8, you will not be able to log in with any not configured user!
To configure u2f for multiple users,
pamu2fcfgtakes the-u <username>option, the output can be appended to theu2f_keysfile like this:$ sudo pamu2fcfg -u <username> >> /etc/Nitrokey/u2f_keys
To add a backup Nitrokey to this user, plug in your backup Nitrokey and do the same you did for the primary user:
$ sudo pamu2fcfg -n >> /etc/Nitrokey/u2f_keys
After that repeat this process for all the users on your system.
Enforcing Nitrokey second factor authentication
Možno ste si všimli, že overovanie pomocou kľúča Nitrokey ešte nebolo zavedené. Po potvrdení, že overovanie pomocou kľúča Nitrokey funguje, ho môžeme vynútiť zmenou príznaku
sufficientnarequired.Varovanie
Pred pokračovaním v tomto kroku sa uistite, že máte:
Otestovali sme, či overovanie pomocou kľúča Nitrokey skutočne funguje, inak môžete stratiť prístup k počítaču.
Nastavte záložný kľúč Nitrokey. V opačnom prípade, ak stratíte alebo rozbijete kľúč Nitrokey, stratíte prístup k svojmu počítaču!
Postupujte opatrne!
Na to je potrebné upraviť konfiguračný súbor
PAM:$ sudo editor /etc/pam.d/common-auth
V riadku, ktorý ste predtým pridali na koniec súboru, zmeňte slovo
sufficientnarequired. Malo by to vyzerať takto:#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¶
Ak dávate prednosť používaniu kľúča Nitrokey ako alternatívy k svojmu heslu (heslo ALEBO Nitrokey), môžete namiesto toho nakonfigurovať túto možnosť:
Configuration Steps:
Presunutie konfiguračného riadku PAM do hornej časti **** ` /etc/pam.d/common-auth` (pred ostatné moduly auth)
Ponechajte si kontrolný príznak
sufficient
To umožňuje overovanie len pomocou jedného z faktorov. Všimnite si, že to poskytuje menšie zabezpečenie ako overovanie druhým faktorom.
Pochopenie režimov overovania
Kombinácia pozície riadku a kontrolného príznaku určuje režim overovania:
Position |
Control Flag |
Authentication Mode |
Use Case |
|---|---|---|---|
Dno (po pam_unix) |
|
Second factor (testing) |
Fáza bezpečného testovania |
Dno (po pam_unix) |
|
Druhý faktor (vynútený) |
Production security (main guide) |
Top (pred pam_unix) |
|
Alternative factor |
Convenience (password OR key) |
Ako funguje PAM:
PAM spracováva moduly postupne zhora nadol. Kontrolný príznak určuje, ako úspech alebo neúspech ovplyvní celkové overenie:
sufficient: Úspech dokončí autentifikáciu; neúspech sa ignoruje, ak ostatné moduly uspejúrequired: Úspech je povinný; neúspech spôsobí celkové zlyhanie autentifikácie
Čo to pre vás znamená:
Alternatívne overovanie (najvyššie + dostatočné):
Môžete sa prihlásiť pomocou svojho hesla ALEBO na len pomocou kľúča Nitrokey.
If authentication with the Nitrokey succeeds, no password is required
Ak overenie pomocou kľúča Nitrokey zlyhá alebo sa vynechá, heslo bude stále fungovať
Je to pohodlnejšie, ale menej bezpečné ako overenie druhým faktorom.
Security implications:
Útočník s vaším heslom sa môže prihlásiť bez vášho Nitrokey
Útočník s fyzickým prístupom k vášmu Nitrokey sa môže prihlásiť bez vášho hesla
Používajte ho len vtedy, ak je pohodlie dôležitejšie ako maximálna bezpečnosť.
Podrobné vysvetlenie kontrolných príznakov a ich dôsledkov nájdete na stránke Kontrolné príznaky.
Moduly PAM¶
Existuje niekoľko súborov modulov PAM, ktoré môžete upraviť podľa svojich potrieb:
By modifying
/etc/pam.d/common-authfile, you will be able to use you Nitrokey for 2nd factor authentication for graphic login andsudo.If you wish to use FIDO U2F authentication solely for Gnome’s graphic login, you might prefer to modify the
/etc/pam.d/gdm-passwordPrípadne môžete len upraviť súbor
/etc/pam.d/sudo, ak chcete používať FIDO U2F pri použití príkazusudo.
Kontrolné príznaky¶
Kontrolný príznak určuje, ako sa modul PAM zachová pri úspešnom alebo neúspešnom overení. V kroku 6 sme použili príznak sufficient na testovanie, potom sme ho zmenili na required na presadzovanie.
K dispozícii sú tieto kontrolné príznaky:
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: Podobne akorequired, avšak v prípade, že konkrétny modul vráti chybu, riadenie sa vráti priamo aplikácii alebo nadradenému zásobníku PAM. Tento príznak vás tiež môže zablokovať v počítači, ak nemáte prístup ku kľúču Nitrokey.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. Thesufficientflag 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. Theoptionalflag is considered safe to use for testing purposes.
Varovanie
If
requiredorrequisiteis 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.Prístup k počítaču stratíte, ak ste nesprávne nakonfigurovali modul PAM a použili príznaky
requiredaleborequisite.Ak nastavíte centrálne mapovanie overovania, stratíte aj možnosť používať
sudoa použili príznakyrequiredaleborequisite.Môžete tiež stratiť možnosť prihlásiť sa pomocou správcu displeja Gnome, ak je vynútené prihlásenie pomocou čipovej karty a použili ste príznaky
requiredaleborequisite. Ďalšie informácie nájdete v časti Riešenie problémov.
Riešenie problémov¶
Problémy s prihlásením do používateľského konta pomocou GDM¶
V niektorých prípadoch, napríklad ak máte nainštalovaný program opencs-pkcs11, môže správca zobrazenia Gnome (GDM) predvolene vynútiť prihlásenie pomocou čipovej karty, akonáhle je pripojená akákoľvek čipová karta (napríklad Nitrokey), aj keď žiadna čipová karta nebola nikdy nakonfigurovaná. To môže zabrániť prihláseniu do vášho používateľského účtu pomocou u2f. Ak ste nastavili kontrolný príznak sufficient, odpojte všetky inteligentné karty a prihláste sa pomocou svojho hesla. Ak chcete vypnúť vynucovanie používania inteligentných kariet, spustite nasledujúci príkaz:
$ 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