Sudo/es

The sudo command provides a simple and secure way to configure privilege escalation, e.g. letting normal users to execute certain (or all) commands as root or some different user, possibly without giving a password.

Cuando quiera que varias personas realicen ciertas tareas administrativas en su sistema sin que tenga que concederles un acceso total como root, el uso de sudo es la mejor opción. Con sudo puede controlar quién puede hacer según qué. Esta guía le ofrece una pequeña introducción a esta maravillosa herramienta.

Conceder Permisos
The package allows the system administrator to grant permission to other users to execute one or more applications they would normally have no right to. Unlike using the  bit on these applications sudo gives a more fine-grained control on who can execute a certain command and when.

With sudo you can make a clear list who can execute a certain application. If you would set the setuid bit, any user would be able to run this application (or any user of a certain group, depending on the permissions used). You can (and probably even should) require the user to provide a password when he wants to execute the application.

Registrar la Actividad
One additional advantage of sudo 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 :)

Configurar Sudo
The sudo configuration is managed by the file. This file should never be edited through nano /etc/sudoers or vim /etc/sudoers or any other editor you might like. When you want to alter this file, you should use visudo.

Esta herramienta se asegura que no haya dos administradores del sistema editando el fichero al mismo tiempo, conserva sus permisos y realiza una comprobación de la sintaxis para cerciorarse de que no se cometan errores fatales en el fichero.

Acerca de esta Guía
This guide is meant as a quick introduction. The package is a lot more powerful than what is described in this guide. It has special features for editing files as a different user (sudoedit</tt>), running from within a script (so it can background, read the password from standard in instead of the keyboard, ...), etc.

Please read the sudo</tt> and sudoers</tt> manual pages for more information.

Sintaxis básica
The most difficult part of sudo</tt> is the syntax. The basic syntax is like so:

This syntax tells sudo</tt> that the user, identified by  and logged in on the system   can execute any of the commands listed in   as the root user. A more real-life example might make this more clear: allow the user swift to execute emerge</tt> if he is logged in on localhost:

The user name can also be substituted with a group name - in this case you should start the group name with a  sign. For instance, to allow any one in the wheel</tt> group to execute emerge</tt>:

You can extend the line to allow for several commands (instead of making a single entry for each command). For instance, to allow the same user to not only run emerge</tt> but also ebuild</tt> and emerge-webrsync</tt> as root:

You can also specify a precise command and not only the tool itself. This is useful to restrict the use of a certain tool to a specified set of command options. The sudo</tt> tool allows shell-style wildcards (AKA meta or glob characters) to be used in pathnames as well as command line arguments in the sudoers file. Note that these are not regular expressions.

Pongamos todo esto a prueba:

The password that sudo</tt> 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.

You should know that sudo</tt> does not alter the  variable: any command you place after sudo</tt> is treated from your environment. If you want the user to run a tool in for instance he should provide the full path to sudo</tt>, like so:

Sintaxis básica con LDAP
El siguiente ajuste USE es necesario para ofrecer soporte LDAP.

Cuando se utiliza sudo con LDAP, sudo también leerá la configuración del servidor LDAP, por lo que necesitará editar estos dos ficheros.

También necesitará añadir la siguiente entrada LDAP para sudo.

Las configuraciones del sudoer en LDAP son similares a los ficheros con algunas diferencias. Por favor, lea más sobre sudo con LDAP en el enlace de abajo página del manual de Sudoers LDAP

(para distinguir correctamente entre lo que son y no son alias, se recomienda utilizar mayúsculas para los alias). Como indudablemente habrá deducido, el alias  sirve para todas los valores posibles.

A sample use of the  alias to allow any user to execute the <tt>shutdown</tt> command if he is logged on locally is:

Another example is to allow the user <tt>swift</tt> to execute the <tt>emerge</tt> 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 <tt>emerge</tt> and <tt>ebuild</tt>) on the system and a group of administrators who can change the password of any user, except root!

Ejecución como no Root
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 <tt>apache</tt> for the web server) and want to allow certain users to perform administrative steps as that user (like killing zombie processes).

Dentro de añada el o los usuarios entre   y   antes del listado de órdenes:

For instance, to allow <tt>swift</tt> to run the <tt>kill</tt> tool as the <tt>apache</tt> or <tt>gorg</tt> user:

With this set, the user can run <tt>sudo -u</tt> to select the user he wants to run the application as:

Mediante la directiva, puede establecer un alias para el usuario con el que se va a ejecutar una aplicación. Su uso es idéntico al de otras directivas  vistas anteriormente.

Contraseñas y Configuraciones por Defecto
By default, <tt>sudo</tt> asks the user to identify himself using his own password. Once a password is entered, <tt>sudo</tt> remembers it for 5 minutes, allowing the user to focus on his tasks and not repeatedly re-entering his password.

Esto, por supuesto, se puede cambiar: puede establecer la directiva  en   para cambiar el comportamiento por defecto para un usuario.

Por ejemplo, para cambiar los cinco minutos preestablecidos a cero (no recordarla nunca):

La opción  haría recordar la contraseña indefinidamente (hasta reiniciar el sistema).

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 <tt>sudo</tt> fails) to  instead of the default 3:

Otra característica interesante es mantener definida la variable  de modo que pueda ejecutar herramientas gráficas:

You can change dozens of default settings using the  directive. Fire up the <tt>sudoers</tt> manual page and search for.

Si, no obstante, desea permitirle a un usuario correr un cierto grupo de órdenes sin proporcionar ningún tipo de contraseña, necesita entonces empezar las órdenes con, así:

Listar Privilegios
To inform yourself what your capabilities are, run <tt>sudo -l</tt> :

Si tiene cualquier orden en que no le pida que introduzca una contraseña, tampoco se le pedirá una contraseña para listar las entradas. De no ser así, se le podría pedir su contraseña si no se recuerda.

Prolongar la Caducidad de la Contraseña
By default, if a user has entered his password to authenticate himself to <tt>sudo</tt>, it is remembered for 5 minutes. If the user wants to prolong this period, he can run <tt>sudo -v</tt> to reset the time stamp so that it will take another 5 minutes before <tt>sudo</tt> asks for the password again.

Lo contrario es quitar la marca de tiempo con <tt>sudo -k</tt>.

Completado de Órdenes en Bash
Los usuario que quieran tener completado de órdenes bash, tendrán que ejecutar esto una sola vez.

Completado de Órdenes en Zshell
Los usuarios que deseen completado de órdenes en zsh para sudo pueden definir lo siguiente en y en  respectivamente.

Con el cambio de arriba, todas las órdenes en las localizaciones, y  estarán disponibles al intérprete de órdenes cuando a la orden se le anteponga 'sudo'.