Los usuarios de Ubuntu Linux pueden estar al corriente de usar el comando del “sudo” en Linux. Es una característica muy útil en Linux que permita a administrador de una máquina de Linux a los privilegios de la “raíz” de la concesión a un usuario o a un grupo particular de usuarios. Puede también ser configurado para limitar este privilegio a unos o más comandos. El equipo de Ubuntu, por ejemplo, ha decidido bloquear al usuario de la raíz de entrar por defecto y en lugar de otro permitir que los usuarios utilicen sudo para realizar tareas administrativas. Tan si usted está utilizando Ubuntu Linux, los privilegios del sudo setup de modo que usted tenga por completo privilegios de la “raíz”. Hechemos una ojeada más cercano los privilegios del sudo de la creación y del configuración en su máquina. Antes de proceder por favor nota que usted no debe intentar el siguiente en un servidor de la producción. Pruebe por favor los ejemplos en esta clase particular en una máquina de la prueba y consiga al corriente de sudo antes de que usted lo intente hacia fuera en un servidor de la producción. el sudo es una herramienta muy de gran alcance y se debe utilizar con la precaución extrema.
A mi conocimiento el paquete del “sudo” envía con todas las distribuciones de Linux. Saltaré tan la instalación y saltaré derecho a la configuración. Para esta clase particular utilizaré una máquina roja de Linux del sombrero. Registro en su máquina de Linux como raíz y hecha funcionar el comando siguiente en la línea de comando:
# visudo
El comando antedicho abrirá la configuración del “sudo”, en la cual está /etc/sudoers, usando el redactor del defecto en su máquina, que es Vim en el míos. Enrolle abajo a la sección donde usted ve el texto siguiente:
¿raíz? ¿? ALL= (TODO) TODO
La desintegración de este sintaxis de la configuración del sudo va como esto. Usted primero define a usuario del `' para cuál usted desea para setup sudo. Entonces viene el hostname del `' donde se permite el comando de funcionar. Éste podía ser un hostname específico o “TODO” como en el ejemplo arriba. Y pasado es el comando del `' para cuál usted desea dar privilegio administrativo al usuario del `'.
De nuevo a la configuración. En Vim voluta abajo a la línea demostrada arriba y golpeada la letra o en su teclado para agregar un de giro nuevo. Ahora agregue el texto siguiente, substituyendo calvin con su propio username:
calvin ALL= (TODO) TODO
Ahorre y salga del archivo usando la combinación dominante siguiente:
Salida: wq
Golpee Vuelta (entre) llave para aplicar estas instrucciones. Ahora hemos dado a calvin del `del usuario' todos los privilegios administrativos usando sudo. Open a new terminal window and log in as the user that you granted sudo privileges to. Let’s test whether the new permissions have been setup correctly by restarting the Apache web server as user ‘calvin’:
#?sudo /etc/init.d/httpd restart
Password:
Stopping httpd: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[ ?OK ?]
Starting httpd: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[ ?OK ?]
The system will now prompt you for a password. Enter the password for your username. And voila! The Apache web server should now restart. You can use this for any other administrative task. Granting complete privileges to a user may not always be the best of ideas. So you can limit the user to a few command with administrative privileges. Let’s say you want the user ‘calvin’ to be allowed to only restart the Apache web server. Open the sudo configuration file using the visudo command and edit the line you entered earlier to look like this:
calvin ALL=(ALL) /etc/init.d/httpd restart
Save and exit the file. Log into the terminal as the user ‘calvin’. Now try restarting Apache with sudo:
# sudo /etc/init.d/httpd restart
Password:
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
Great. It works. Now try stopping the web server:
# sudo /etc/init.d/httpd stop
Password:
Sorry, user calvin is not allowed to execute ‘/etc/init.d/httpd stop’ as root on commons.
So as you can see, the user ‘calvin’ can only do what we allow him to do, nothing more. You can add multiple commands in the sudoers file separated by commas. So if you want to allow ‘calvin’ the permission to stop and restart the web server your configuration would read like this:
calvin ALL=(ALL) /etc/init.d/httpd restart,/etc/init.d/httpd stop
Now try stopping the web server, and it should work:
# sudo /etc/init.d/httpd stop
Password:
Stopping httpd: [ OK ]
Another feature of sudo that is pretty useful, particularly if you need to perform an administrative task using a shell script, is setting the sudo privilege without being prompted for a password. Remember that it may not be advisable to do this on a production machine using a username that is shared, because if the password for your username falls into the wrong hands it can spell trouble. So use this feature with caution.
Open the sudoers file and edit the line you entered earlier to look like this:
calvin ALL=(ALL) /etc/init.d/httpd restart NOPASSWD: ALL
The last part of the configuration instructs sudo to not prompt for or expect a password, and allow the user to execute the command that is assigned to it with administrative privileges. Save the file and exit from your text editor and try restart Apache:
# sudo /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
There is a lot more customization that can be done to the sudo configuration file. We have just looked at a small segment of it. However, this ought to give you a start. Again, please use it with caution.





























{ 2 trackbacks }
{ 0 comments… add one now }
Leave a Comment