Sudo/fr

La commande procure un moyen sûr et simple de configurer une escalade de privilèges, par exemple, permettre à des utilisateurs normaux d'exécuter certaines (ou toutes les) commandes en tant que root ou au nom d'un autre utilisateur, sans qu'ils aient à connaître le mot de passe de l'utilisateur auquel ils se substituent.

Lorsque vous voulez que certaines personnes accomplissent certaines tâches administratives sans leur donner un accès total en tant que root, utiliser est la meilleure option. En effet, permet de contrôler qui peut faire quoi. Ce guide est une petite introduction à ce puissant outil.

Cet article est une rapide introduction. Le paquet est bien plus puissant que ce qui est décrit ici. Il a des options supplémentaires permettant l'édition de fichier en tant qu'autre utilisateur, s'exécuter depuis un script (donc reste en arrière-plan, lit le mot de passe depuis l'entrée standard et non depuis le clavier,…), etc.

Merci de lire les pages de manuel de et de  pour plus d'informations.

Journalisation
One additional advantage of is that it can log any attempt (successful or not) to run an application. This is very useful if you want to track who made that one fatal mistake that took you 10 hours to fix :)

Accorder des autorisations
Le paquet permet à l'administrateur système d'autoriser certains utilisateurs à exécuter des applications auxquelles ils n'ont normalement pas accès. À la différence de, permet un contrôle plus fin de qui peut exécuter une certaine commande, et quand.

With you can make a clear list of who can execute a certain application. If you set the setuid bit on an executable, any user would be able to run the application (or any user of a certain group, depending on the permissions used). With you can (and probably should) require the user to provide a password in order to execute the application.

The configuration is managed by the  file. This file should never be edited through or, or any other editor you would normally use. When you want to alter the file, you should always use. This tool makes sure that no two system administrators are editing this file at the same time, preserves the permissions on the file, and performs some syntax checking to make sure you make no fatal mistakes in the file.

Syntaxe de base
The most difficult part of is the  syntax. The basic syntax is as follows:

This line tells that the user, identified by   and logged in on the system , can execute the command   (which can also be a comma-separated list of allowed commands).

A more real-life example might make this more clear: To allow the user to execute  when he is logged in on :

The user name can also be substituted with a group name, in which case the name is prefaced by a  sign. For instance, to allow any one in the group to execute :

To enable more than one command for a given user on a given machine, multiple commands can be listed on the same line. For instance, to allow to not only run  but also  and  as root:

You can also specify a precise command line (including parameters and arguments) not just the name of the executable. This is useful to restrict the use of a certain tool to a specified set of command options. The tool allows shell-style wildcards (AKA meta or glob characters) to be used in path names as well as command-line arguments in the sudoers file. Note that these are not regular expressions.

Here is an example of from the perspective of a first-time user of the tool who has been granted access to the full power of :

The password that requires is the user's own password. This is to make sure that no terminal that you accidentally left open to others is abused for malicious purposes.

Syntaxe de base avec LDAP
The  and   USE flags are needed for the LDAP support.

Lorsque vous utilisez sudo avec LDAP, sudo lira la configuration depuis le serveur LDAP Server également. C'est pourquoi vous devez éditer deux fichiers.

Vous devez aussi ajouter l'entrée LDAP suivante pour sudo.

La configuration des sudoer sur LDAP est similaire à celles des fichiers avec quelques différences. Lisez à propos de sudo avec LDAP à partir du lien ci-dessous.

Utiliser des alias
In larger environments having to enter all users over and over again (or hosts, or commands) can be a daunting task. To ease the administration of you can define aliases. The format to declare aliases is quite simple:

Un alias qui marche toujours, pour toute position, est l'alias  (pour faire une distinction claire entre ce qui est un alias et ce qui ne l'est pas, il est recommandé d'utiliser des lettres capitales  dans les alias). Comme vous l'avez sans doute déduit, l'alias  est un alias représentant tout ce qui est possible en matière de réglage.

A sample use of the  alias to allow any user to execute the  command if he is logged on locally is:

Another example is to allow the user to execute the  command as root, regardless of where he is logged in from:

More interesting is to define a set of users who can run software administrative applications (such as and ) on the system and a group of administrators who can change the password of any user, except root!

Non-root execution
It is also possible to have a user run an application as a different, non-root user. This can be very interesting if you run applications as a different user (for instance for the web server) and want to allow certain users to perform administrative steps as that user (like killing zombie processes).

Inside you list the user(s) in between   and   before the command listing:

For instance, to allow to run the  tool as the  or  user:

With this set, the user can run to select the user he wants to run the application as:

You can set an alias for the user to run an application as using the  directive. Its use is identical to the other  directives we have seen before.

Passwords and default settings
By default, asks the user to identify himself using his own password. Once a password is entered, remembers it for 5 minutes, allowing the user to focus on his tasks and not repeatedly re-entering his password.

Of course, this behavior can be changed: you can set the  directive in  to change the default behavior for a user.

For instance, to change the default 5 minutes to 0 (never remember):

A setting of  would remember the password indefinitely (until the system reboots).

A different setting would be to require the password of the user that the command should be run as and not the users' personal password. This is accomplished using. In the following example we also set the number of retries (how many times the user can re-enter a password before fails) to   instead of the default 3:

Another interesting feature is to keep the  variable set so that you can execute graphical tools:

You can change dozens of default settings using the  directive. Fire up the manual page and search for.

If you however want to allow a user to run a certain set of commands without providing any password whatsoever, you need to start the commands with, like so:

Bash completion
Users that want bash completion with sudo need to run this once.

Zshell completion
Users that want zsh completion for sudo can set the following in and  respectively

With the above change, all commands in the, and  locations will be available to the shell for completion when the command is prefaced with 'sudo'.

Lister les privilèges
To inform yourself what your capabilities are, run :

Si des commandes se trouvent dans qui ne requièrent pas que vous saisissiez un mot de passe, il ne sera pas non plus nécessaire de saisir un mot de passe pour lister les entrées. Autrement, on pourrait vous demander votre mot de passe s'il n'est pas mémorisé.

Prolonger le temps de mémorisation du mot de passe
By default, if a user has entered their password to authenticate their self to, it is remembered for 5 minutes. If the user wants to prolong this period, he can run to reset the time stamp so that it will take another 5 minutes before  asks for the password again.

The inverse is to kill the time stamp using.