Une introduction à la commande de sudo et la configuration classent

par Sukrit Dhandhania sur 29 décembre 2008

Linux

Les utilisateurs d'Ubuntu Linux peuvent être au courant d'employer la commande de « sudo » dans Linux. C'est un dispositif très utile dans Linux qui permet l'administrateur d'une machine de Linux aux privilèges de « racine » de concession à un utilisateur ou à un groupe particulier d'utilisateurs. Il peut également être configuré de sorte que ce privilège soit limité à une ou plusieurs commandes. L'équipe d'Ubuntu, par exemple, ont décidé de bloquer l'utilisateur de racine d'entrer par défaut et permettre à la place à des utilisateurs d'employer le sudo pour exécuter administratif charge. Ainsi si vous employez Ubuntu Linux, des privilèges de sudo ont été installés de sorte que vous ayez complètement des privilèges de « racine ». Jetons un coup d'oeil plus étroit les privilèges d'établissement et de configuration à sudo sur votre machine. Avant veuillez procéder note que vous ne devriez pas essayer le suivant sur un serveur de production. Veuillez essayer les exemples dans ce cours d'instruction sur une machine d'essai et obtenez au courant du sudo avant que vous l'essayiez dehors sur un serveur de production. le sudo est un outil très puissant et doit être employé avec l'attention extrême.

À ma connaissance le paquet de « sudo » se transporte avec toutes les distributions de Linux. Ainsi je sauterai l'installation et sauterai directement à la configuration. Pour ce cours d'instruction j'utiliserai une machine rouge de Linux de chapeau. Notation dans votre machine de Linux comme racine et courue la commande suivante sur la ligne de commande :

# visudo

La commande ci-dessus ouvrira la configuration de « sudo », à la laquelle est /etc/sudoers, en utilisant le rédacteur de défaut sur votre machine, qui est Vim sur le mien. Faites défiler vers le bas à la section où vous voyez le texte suivant :

racine ? ? ALL= (TOUT) TOUT

La dissolution de cette syntaxe de configuration de sudo va comme ceci. Vous définissez d'abord l'utilisateur de `' pour ce que vous voulez pour installer le sudo. Vient alors le hostname de `' où on permet la commande de courir. Ceci a pu être un hostname spécifique ou « TOUS » en tant que dans l'exemple ci-dessus. Et dernière est la commande de `' pour ce qui vous veulent privilège administratif donner de `utilisateur'.

De nouveau à la configuration. Dans Vim le rouleau vers le bas à la ligne montrée ci-dessus et frappée la lettre o sur votre clavier pour ajouter un d'interligne. Ajoutez maintenant le texte suivant, remplaçant calvin avec votre propre username :

calvin ALL= (TOUT) TOUT

Sauvez et sortez le dossier en utilisant la combinaison principale suivante :

ESC : wq

Frappez Retour (entrez) clef pour appliquer ces instructions. Nous avons maintenant donné au calvin de `d'utilisateur' tous les privilèges administratifs en utilisant le 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.

Related Posts:
  • How to install, setup and use Avant Window Navigator (Awn) in Ubuntu Feisty
  • How to play .rmvb files in Ubuntu
  • How to setup Virtual Hosts in Apache
  • How to set the date on your Linux machine
  • How to use your Nokia N95 as a wireless Webcam
  • Get Simple Help tutorials just like this one in your email inbox every day - for free! Just enter your email address below:

    You can always opt out of this email subscription at any time.


    Bookmark and Share

    { 2 trackbacks }

    Daily Digest for 2009-01-02
    01.02.09 at 4:03 pm
    Outrora, eu » Blog Archive » Links dos dias January 6th a January 12th
    01.12.09 at 9:06 am

    { 0 comments… add one now }

    Leave a Comment

    You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>