Ubuntu Linux användare kan vara förtrogen med genom att använda ”sudoen” befaller i Linux. Det är ett mycket användbart särdrag i Linux som låter administratören av en Linux bearbetar med maskin för att bevilja ”rotar” privilegierar till en särskild användare eller grupp av användare. Det kan också konfigureras, så att detta privilegierar begränsas till one or more befaller. Det Ubuntu laget, till exempel, har avgjort till kvarteret rotaanvändaren från inloggning av standard och låter i stället användare använda sudo för att utföra administrativa uppgifter. , om så du använder Ubuntu Linux, privilegierar har sudoen varit ställer in, så att du har mycket ”att rota” privilegierar. Låt oss ta en mer nära look på inställning - upp och konfigurera sudo privilegierar på ditt bearbetar med maskin. Notera att du inte bör försök efter på en produktionserver, för förfarandet behar. Behaga försök ut som exemplen i denna tutorial på en testa bearbetar med maskin, och få den förtrogen med sudoen för dig försök det ut på en produktionserver. sudoen är ett mycket kraftigt bearbetar och måste användas med ytterlighet varnar.
Till min kunskap ”paketerar sudoen” ships med alla Linux fördelningor. Så ska hoppar jag överhopp installationen och raksträcka till konfigurationen. För denna tutorial ska jag bruk som en röd hatt Linux bearbetar med maskin. Logga in i din Linux bearbetar med maskin som rotar och kör befalla på befalla fodrar efter:
# visudo
De ovannämnda befaller ska öppet ”den sudo” konfigurationen, som är på /etc/sudoers, genom att använda standardredaktören på ditt bearbeta med maskin, som är Vim på min. Snirkeln besegrar till dela upp var du ser efter texten:
rota? ? ALL= (ALLA) ALLA
Upplösningen av denna sudokonfigurationsyntax går något liknande detta. Du definierar först `- användaren' för vilket du önskar att ska ställa in sudo. Därefter kommer `- hostnamen' var befalla är tillåten att köra. Detta kunde vara ”ALL” en specifik hostname eller som i exemplet över. Och sist är `en befaller' för vilket du önskar att ska ge den administrativa `- användaren' privilegierar.
Baksida till konfigurationen. I Vim snirkel besegra till fodra som över visas och, slå märka nolla på ditt skriva för att tillfoga en ny rad. Tillfoga nu efter texten som byter ut calvin med din egna username:
calvin ALL= (ALLA) ALLA
Räddningen och går ut spara genom att använda den efter nyckel- kombinationen:
ESC: wq
Slå Retur (skriv in), stämma för att applicera dessa anvisningar. Vi har nu givit användare`- calvinen,' som allt administrativt privilegierar genom att använda 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