Ubuntu Linux Benutzer können mit dem Verwenden des „sudo“ Befehls in Linux vertraut sein. Es ist eine sehr nützliche Eigenschaft in Linux, das einem bestimmten Benutzer oder einer Gruppe Benutzern den Verwalter einer Linux Maschine Bewilligung „zu den Wurzel“ Privilegien erlaubt. Es kann auch zusammengebaut werden, damit dieses Privileg auf eine oder mehrer Befehle begrenzt wird. Die Ubuntu Mannschaft z.B. haben entschieden, den Wurzelbenutzer vom Anmelden durch Rückstellung zu blockieren und Benutzern anstatt zu erlauben, sudo zu verwenden, um administrative Aufgaben durchzuführen. So, wenn Sie Ubuntu Linux verwenden, sind sudo Privilegien gegründet worden, damit Sie voll „Wurzel“ Privilegien haben. Lassen Sie uns Aufstellung und Konfiguration sudo genau betrachten Privilegien auf Ihrer Maschine. Bevor bitte fortfahren Anmerkung, daß Sie nicht das folgende auf einem Produktion Bediener versuchen sollten. Probieren Sie bitte die Beispiele in diesem Tutorial auf einer Testmaschine aus und erhalten Sie mit sudo vertraut, bevor Sie es heraus auf einem Produktion Bediener versuchen. sudo ist ein sehr leistungsfähiges Werkzeug und muß mit extremer Vorsicht verwendet werden.
Meines Wissens versendet das „sudo“ Paket mit allen Linux Verteilungen. So überspringe ich die Installation und springe gerade zur Konfiguration. Für diesen Tutorial benutze ich eine rote Hut Linux Maschine. Maschinenbordbuch in Ihre Linux Maschine als Wurzel und laufen gelassen dem folgenden Befehl auf der Befehl Linie:
# visudo
Der oben genannte Befehl öffnet die „sudo“ Konfiguration, der an ist /etc/sudoers, den Rückstellung Herausgeber auf Ihrer Maschine verwendend, die Vim auf meinen ist. Scroll unten zum Abschnitt, in dem Sie den folgenden Text sehen:
Wurzel? ? ALL= (ALLE) ALLE
Das Auseinanderbrechen dieser sudo Konfiguration Syntax geht so. Sie definieren zuerst den `Benutzer' für, welches Sie sudo gründen wünschen. Kommt dann das `hostname', wo der Befehl zu laufen erlaubt wird. Dieses konnte ein spezifisches hostname oder „ALLE“ als im Beispiel oben sein. Und ist der `Befehl' letzt für, welche Sie administratives Privileg geben möchten des `Benutzers'.
Zurück zu der Konfiguration. Vim in der Rolle unten zur Linie oben gezeigt und geschlagen dem Buchstaben O auf Ihrer Tastatur, zum ein neues Zeilen- zu addieren. Addieren Sie jetzt den folgenden Text und ersetzen calvin mit Ihrem eigenen username:
calvin ALL= (ALLE) ALLE
Speichern Sie und nehmen Sie die Akte mit der folgenden Tastenkombination heraus:
ESC: wq
Schlagen Sie Rückkehr (kommen Sie) herein, der Schlüssel, zum dieser Anweisungen anzuwenden. Wir haben dem Benutzer `calvin' alle administrativen Privilegien jetzt mit sudo gegeben. 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