Μια εισαγωγή στο αρχείο εντολής και διαμόρφωσης sudo

από Sukrit Dhandhania [[on]] 29 Δεκεμβρίου 2008

Linux

Οι χρήστες Linux Ubuntu μπορούν να εξοικειωθούν με τη χρησιμοποίηση της εντολής «sudo» σε Linux. Είναι ένα πολύ χρήσιμο χαρακτηριστικό γνώρισμα σε Linux που επιτρέπει στο διοικητή μιας μηχανής Linux στα προνόμια «ρίζας» επιχορήγησης σε έναν συγκεκριμένη χρήστη ή μια ομάδα χρηστών. Μπορεί επίσης να διαμορφωθεί έτσι ώστε αυτό το προνόμιο περιορίζεται σε μια ή περισσότερες εντολές. Η ομάδα Ubuntu, παραδείγματος χάριν, έχει αποφασίσει να εμποδίσει το χρήστη ρίζας από να συνδεθεί εξ ορισμού και να επιτρέψει αντ' αυτού στους χρήστες για να χρησιμοποιήσει το sudo για να εκτελέσει τους διοικητικούς στόχους. Έτσι εάν χρησιμοποιείτε Ubuntu Linux, τα προνόμια sudo είναι οργάνωση έτσι ώστε έχετε τα πλήρη προνόμια «ρίζας». Ρίξτε μια πιό στενή ματιά στα προνόμια sudo καθιέρωσης και διαμόρφωσης στη μηχανή σας. Πριν από προχωρώντας παρακαλώ τη σημείωση ότι δεν πρέπει να δοκιμάσετε τον ακόλουθο σε έναν κεντρικό υπολογιστή παραγωγής. Παρακαλώ δοκιμάστε τα παραδείγματα σε αυτό το σεμινάριο σε μια μηχανή δοκιμής και εξοικειωθείτε με το sudo προτού να το δοκιμάσετε έξω σε έναν κεντρικό υπολογιστή παραγωγής. το sudo είναι ένα πολύ ισχυρό εργαλείο και πρέπει να χρησιμοποιηθεί με την ακραία προσοχή.

Στη γνώση μου η συσκευασία «sudo» στέλνει με όλες τις διανομές Linux. Έτσι θα πηδήσω την εγκατάσταση και θα πηδήσω κατ' ευθείαν στη διαμόρφωση. Για αυτό το σεμινάριο θα χρησιμοποιήσω μια κόκκινη μηχανή Linux καπέλων. Κούτσουρο στη μηχανή Linux σας ως ρίζα και τρεγμένος την ακόλουθη εντολή στη γραμμή εντολής:

# visudo

Η ανωτέρω εντολή θα ανοίξει τη διαμόρφωση «sudo», η οποία είναι /etc/sudoers, χρησιμοποιώντας τον προκαθορισμένο επεξεργαστή στη μηχανή σας, η οποία είναι Vim στο ορυχείο. Κύλινδρος κάτω στο τμήμα όπου βλέπετε το ακόλουθο κείμενο:

ρίζα; ; ALL= (ΟΛΟΙ) ΟΛΟΙ

Η αποσύνθεση αυτής της σύνταξης διαμόρφωσης sudo πηγαίνει όπως αυτό. Καθορίζετε αρχικά το χρήστη `» για το οποίο θέλετε στο sudo οργάνωσης. Κατόπιν έρχεται το `hostname» όπου η εντολή επιτρέπεται για να τρέξει. Αυτό θα μπορούσε να είναι ένα συγκεκριμένο hostname ή «ΟΛΑ» όπως στο παράδειγμα ανωτέρω. Και διαρκέστε είναι η εντολή `» για την οποία θέλετε να δώσετε στο χρήστη `» το διοικητικό προνόμιο.

Πίσω στη διαμόρφωση. Σε Vim κύλινδρο κάτω στη γραμμή που παρουσιάζεται ανωτέρω και που χτυπιέται την επιστολή ο στο πληκτρολόγιό σας για να προσθέσει μια νέα γραμμή. Τώρα προσθέστε το ακόλουθο κείμενο, αντικατάσταση calvin με το όνομα χρήστη σας:

CALVIN ALL= (ΌΛΟΙ) ΌΛΑ

Εκτός από και βγείτε το αρχείο χρησιμοποιώντας τον ακόλουθο βασικό συνδυασμό:

ΟΚΕ: wq

Χτυπήστε Επιστροφή (εισάγετε) κλειδώστε για να εφαρμόσετε αυτές τις οδηγίες. Έχουμε δώσει τώρα στο calvin χρηστών `» όλα τα διοικητικά προνόμια χρησιμοποιώντας το 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.

If this post helped you, I would be extremely grateful if you could take 3 minutes (I timed it) to complete this survey. If you enter your email address at the end of the survey, you'll be entered into a contest to win a $25 USD Amazon Gift Certificate. You do not need to enter your name or email address (though you won't be entered into the contest) to complete the survey. No personally identifiable information is gathered. If you do opt to enter the contest, your email address will not be sold or used for any kind of communication, other than to notify you if you won the contest. After the contest ends all email addresses will be deleted. Thanks very much in advance!!
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.

    { 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>