« Security/PamUsb/GettingStarted » : différence entre les versions

De TartareFR
Aller à la navigation Aller à la recherche
Ligne 148 : Ligne 148 :
remove the device, and deactivate it when you plug the device back.
remove the device, and deactivate it when you plug the device back.


GNOME (gnome-screensaver):
'''GNOME (gnome-screensaver)''':
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<user id="didier">
<user id="didier">
Ligne 157 : Ligne 157 :
</syntaxhighlight>
</syntaxhighlight>


KDE3 (kscreensaver via DCOP):
'''KDE3 (kscreensaver via DCOP)''':
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<user id="didier">
<user id="didier">
Ligne 166 : Ligne 166 :
</syntaxhighlight>
</syntaxhighlight>


KDE4 (kscreensaver via DBUS):
'''KDE4 (kscreensaver via DBUS)''':
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<user id="didier">
<user id="didier">
Ligne 195 : Ligne 195 :
of autostarted applications so it will be started automatically.
of autostarted applications so it will be started automatically.


GNOME:
'''GNOME''':
# Open System -> Preferences -> Sessions
# Open System -> Preferences -> Sessions
# Select Startup Programs and press Add
# Select Startup Programs and press Add
Ligne 201 : Ligne 201 :
# Press Close
# Press Close


KDE: Ajout d'un script dans le répertoire Autostart de KDE.
'''KDE''': Ajout d'un script dans le répertoire Autostart de KDE.
<pre>$ echo -e '#!/bin/bash\n/usr/bin/pamusb-agent 1>/dev/null 2>&1' > ~/.kde/Autostart/pamusb-agent.sh</pre>
<pre>$ echo -e '#!/bin/bash\n/usr/bin/pamusb-agent 1>/dev/null 2>&1' > ~/.kde/Autostart/pamusb-agent.sh</pre>



Version du 31 décembre 2012 à 10:52

Getting Started

Setting up pam_usb requires the following, Install:

  1. Set up devices and users
  2. Configuring PAM for system authentication
  3. (Optional) Configuring pamusb-agent to run programs when the device is inserted or removed

Setting up Devices and Users

Once you've connected your USB device to the computer, use pamusb-conf to add it to the configuration file:

# pamusb-conf --add-device root-key
Please select the device you wish to add.
* Using "USB Flash Disk (FBF1101121100745)" (only option)

Which volume would you like to use for storing data ?
0) /dev/sdc1 (UUID: 335F405C0A8030B0)
1) /dev/sdc2 (UUID: e8117c04-6769-49ee-b0bc-3b55252947a9)
2) /dev/sdc3 (UUID: 3ea9b653-a346-4827-85a8-b809bcec4028)
3) /dev/sdc4 (UUID: 24f0b890-94b7-412e-b11c-5f226195749b)

[0-3]: 1

Name            : root-key
Vendor          : USB
Model           : Flash Disk
Serial          : FBF1101121100745
UUID            : e8117c04-6769-49ee-b0bc-3b55252947a9

Save to /etc/pamusb.conf ?
[Y/n] y
Done.
# pamusb-conf --add-device didier-key
Please select the device you wish to add.
* Using "USB Flash Disk (FBF1101121100745)" (only option)

Which volume would you like to use for storing data ?
0) /dev/sdc1 (UUID: 335F405C0A8030B0)
1) /dev/sdc2 (UUID: e8117c04-6769-49ee-b0bc-3b55252947a9)
2) /dev/sdc3 (UUID: 3ea9b653-a346-4827-85a8-b809bcec4028)
3) /dev/sdc4 (UUID: 24f0b890-94b7-412e-b11c-5f226195749b)

[0-3]: 2

Name            : didier-key
Vendor          : USB
Model           : Flash Disk
Serial          : FBF1101121100745
UUID            : 3ea9b653-a346-4827-85a8-b809bcec4028

Save to /etc/pamusb.conf ?
[Y/n] y
Done.
Note.png
Device Name
Device name can be any arbitrary name you'd like. Also, you can add as many devices as you want.

Next, configure users you want to be able to authenticate with pam_usb:

# pamusb-conf --add-user root
Which device would you like to use for authentication ?
0) root-key
1) didier-key

[0-1]: 0

User            : root
Device          : root-key

Save to /etc/pamusb.conf ?
[Y/n] y
Done.
# pamusb-conf --add-user didier
Which device would you like to use for authentication ?
0) root-key
1) didier-key

[0-1]: 1

User            : didier
Device          : didier-key

Save to /etc/pamusb.conf ?
[Y/n] y
Done.

Check the configuration

You can run pamusb-check anytime to check if everything is correctly worked. This tool will simulate an authentication request (requires your device to be connected, otherwise it will fail).

# pamusb-check root
* Authentication request for user "root" (pamusb-check)
* Device "MyDevice" is connected (good).
* Performing one time pad verification...
* Verification match, updating one time pads...
* Access granted.

Setting up the PAM module

To add pam_usb into the system authentication process, we need to edit <path>/etc/pam.d/common-auth</path>

Note.png
If you are using RedHat or Fedora
This file can be known as /etc/pam/system-auth.

Your default PAM common-auth configuration should include the following line:

auth    required        pam_unix.so nullok_secure

This is a current standard which uses passwords to authenticate a user.

Alter your /etc/pam.d/common-auth configuration to:

auth    sufficient      pam_usb.so
auth    required        pam_unix.so nullok_secure

The suffient keyword means that if pam_usb allows the authentication, then no password will be asked. If the authentication fails, then the default password-based authentication will be used as fallback.

If you change it to required, it means that *both* the USB flash drive and the password will be required to grant access to the system.

At this point, you should be able to authenticate with the relevant USB device plugged-in.

scox $ su
* pam_usb v.SVN
* Authentication request for user "root" (su)
* Device "MyDevice" is connected (good).
* Performing one time pad verification...
* Verification match, updating one time pads...
* Access granted.

Agent

The pam_usb agent (pamusb-agent) allows you to automatically execute commands upon locking and unlocking events. Those events are generated when you insert or remove your authentication device. To configure the commands, you have to edit pam_usb's configuration file (<path>/etc/pamusb.conf</path>) and add agent entries into your user section.

For instance, you could automatically start your screensaver as soon as you remove the device, and deactivate it when you plug the device back.

GNOME (gnome-screensaver):

<user id="didier">
  <device>didier-key</device>
  <agent event="lock">gnome-screensaver-command --lock</agent>
  <agent event="unlock">gnome-screensaver-command --deactivate</agent>
</user>

KDE3 (kscreensaver via DCOP):

<user id="didier">
  <device>didier-key</device>
  <agent event="lock">dcop kdesktop KScreensaverIface lock</agent>
  <agent event="unlock">dcop kdesktop KScreensaverIface quit</agent>
</user>

KDE4 (kscreensaver via DBUS):

<user id="didier">
  <device>didier-key</device>
  <agent event="lock">qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock</agent>
  <agent event="unlock">qdbus org.kde.screenlocker /MainApplication quit</agent>
</user>
Note.png
More commands
You can execute more commands by adding extra <agent> entries.
$ ./pamusb-agent
pamusb-agent[31915]: pamusb-agent up and running.
pamusb-agent[31915]: Watching device "didier-key" for user "didier"
pamusb-agent[31915]: Device "didier-key" has been removed, locking down user "didier"...
pamusb-agent[31915]: Running "qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock"

pamusb-agent[31915]: Locked.
pamusb-agent[31915]: Device "didier-key" has been inserted. Performing verification...
pamusb-agent[31915]: Executing "/usr/bin/pamusb-check --quiet --config=/etc/pamusb.conf --service=pamusb-agent didier"
pamusb-agent[31915]: Authentication succeeded. Unlocking user "didier"...
pamusb-agent[31915]: Running "qdbus org.kde.screenlocker /MainApplication quit"

pamusb-agent[31915]: Unlocked.

Depending on your desktop environment, you have to add pamusb-agent to the list of autostarted applications so it will be started automatically.

GNOME:

  1. Open System -> Preferences -> Sessions
  2. Select Startup Programs and press Add
  3. Enter pamusb-agent and press OK
  4. Press Close

KDE: Ajout d'un script dans le répertoire Autostart de KDE.

$ echo -e '#!/bin/bash\n/usr/bin/pamusb-agent 1>/dev/null 2>&1' > ~/.kde/Autostart/pamusb-agent.sh

Fine Tuning

There are many options available configure pam_usb.

Check out the Configuration File.