Running cryptsetup commands without sudo permissions
You can give your users (or groups) limited sudo
access to just these commands.
Use visudo
to edit the sudoers
file (sudo
configuration). It will open it in default editor and validate it once you're done to prevent breaking sudo
. Add these at the end:
usernameOr%Groupname ALL=(root) NOPASSWD: /sbin/cryptsetup luksOpen /dev/dev1 mapper_name1
usernameOr%Groupname ALL=(root) NOPASSWD: /sbin/cryptsetup luksOpen /dev/dev1 mapper_name2
usernameOr%Groupname ALL=(root) NOPASSWD: /sbin/cryptsetup luksClose mapper_name1
usernameOr%Groupname ALL=(root) NOPASSWD: /sbin/cryptsetup luksClose mapper_name2
Breakdown of these lines:
-
usernameOr%Groupname
- substitute with username or group name prefixed with%
-
ALL
allows all hosts (I don't know how this affectssudo
in practice, it seems likeALL
is okay most of the time) -
(root)
means that they can only impersonate root -
NOPASSWD:
skips password prompt, remove this part to prompt for password -
/sbin/cryptsetup luksOpen /dev/dev1 mapper_name1
is obviously your command, with a fully qualified path to the executable