De gebruikers van Linux van Ubuntu kunnen vertrouwd zijn met het gebruiken van het „sudo“ bevel in Linux. Het is een zeer nuttige eigenschap in Linux die de beheerder van een machine Linux de voorrechten aan van de toelage „wortel“ aan een bepaalde gebruiker of een groep gebruikers toestaat. Het kan ook worden gevormd zodat dit voorrecht tot één of meerdere bevelen beperkt is. Het team Ubuntu, bijvoorbeeld, heeft beslist de wortelgebruiker te blokkeren van het het programma openen door gebrek en in plaats daarvan gebruikers toe te staan om sudo te gebruiken om administratieve taken uit te voeren. Zo als u Ubuntu Linux gebruikt, zijn de sudovoorrechten opstelling geweest zodat u volledige „wortel“ voorrechten hebt. Neem een dichtere blik bij vestiging en het vormen sudovoorrechten op uw machine. Alvorens gelieve te werk te gaan nota dat u niet het volgende op een productieserver zou moeten proberen. Probeer gelieve de voorbeelden in dit leerprogramma op een testmachine uit en vertrouwd met sudo te worden alvorens u het op een productieserver uitprobeert. sudo is een zeer krachtig hulpmiddel en moet met extreme voorzichtigheid worden gebruikt.
Aan mijn kennis verscheept het „sudo“ pakket met alle distributies Linux. Zo zal ik de installatie overslaan en zal rechtstreeks aan de configuratie springen. Voor dit leerprogramma zal ik een Rode machine van Linux van de Hoed gebruiken. Logboek in uw machine Linux als wortel en in werking gesteld het volgende bevel op de bevellijn:
# visudo
Het bovengenoemde bevel zal de „sudo“ configuratie openen, die bij is /etc/sudoers, gebruikend de standaardredacteur op uw machine, die Vim op mijn is. Rol neer aan de sectie waar u de volgende tekst ziet:
wortel? ? ALL= (ALLEN) ALLEN
Het verbreken van deze syntaxis van de sudoconfiguratie gaat als dit. U bepaalt eerst de gebruiker `' voor wat u aan opstellingssudo wilt. Dan komt `hostname' waar het bevel om wordt toegestaan te lopen. Dit zou kunnen zijn één specifieke hostname of „hierboven ALLEN“ zoals in het voorbeeld. En duur is het bevel `' waarvoor u de gebruiker `' administratief voorrecht wilt geven.
Terug naar de configuratie. In Vim rol neer aan de lijn hierboven getoond en geraakt de brief o op uw toetsenbord om een nieuwe lijn toe te voegen. Voeg nu de volgende tekst, het vervangen toe calvin met uw eigen gebruikersbenaming:
CALVIN ALL= (ALLEN) ALLEN
Sparen en ga het dossier weg gebruikend de volgende belangrijkste combinatie:
ESC: wq
Raak Terugkeer (ga) binnen sluit om deze instructies toe te passen. Wij hebben nu gebruikers`calvin' alle administratieve voorrechten gebruikend sudo gegeven. 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