Ubuntu Linux users may be familiar with using the “sudo” command in Linux. Ubuntu Linux-brukere kan bli kjent med å bruke "sudo" kommandoen i Linux. It's a very useful feature in Linux that allows the administrator of a Linux machine to grant “root” privileges to a particular user or group of users. Det er en svært nyttig funksjon i Linux som gjør det mulig for administratoren av en Linux-maskin til å gi "root" privilegier til en bestemt bruker eller en gruppe av brukere. It can also be configured so that this privilege is limited to one or more commands. Den kan også konfigureres slik at dette privilegiet er begrenset til én eller flere kommandoer. The Ubuntu team, for example, have decided to block the root user from logging in by default and instead allow users to use sudo to perform administrative tasks. Ubuntu-teamet, for eksempel, har besluttet å blokkere root brukeren logge inn som standard, og i stedet la brukerne bruke sudo for å utføre administrative oppgaver. So if you are using Ubuntu Linux, sudo privileges have been setup so that you have full “root” privileges. Så hvis du bruker Ubuntu Linux, har sudo privilegier blitt oppsett slik at du har full "root" privilegier. Let's take a closer look at setting up and configuring sudo privileges on your machine. La oss ta en nærmere titt på oppsett og konfigurering av sudo-rettigheter på maskinen. Before proceeding please note that you should not try the following on a production server. Før du fortsetter oppmerksom på at du ikke bør prøve følgende på en produksjons server. Please try out the examples in this tutorial on a test machine and get familiar with sudo before you try it out on a production server. Vennligst prøv ut eksemplene i denne opplæringen på en test maskin og bli kjent med sudo før du prøver det ut på en produksjons server. sudo is a very powerful tool and must be used with extreme caution. sudo er en meget kraftig verktøy, og må brukes med ekstrem forsiktighet.
To my knowledge the “sudo” package ships with all Linux distributions. Til min kunnskap på "sudo" pakken leveres med alle Linux-distribusjoner. So I'll skip the installation and jump straight to the configuration. Så jeg må hoppe over installasjonen og hoppe rett til konfigurasjonen. For this tutorial I will use a Red Hat Linux machine. For denne opplæringen vil jeg bruke en Red Hat Linux-maskin. Log into your Linux machine as root and run the following command on the command line: Logg inn på din Linux-maskin som root og kjør følgende kommando på kommandolinjen:
# visudo # Visudo
The above command will open the “sudo” configuration, which is at /etc/sudoers , using the default editor on your machine, which is Vim on mine. Det over kommandoen vil åpne "sudo" konfigurasjon, som er i / etc / sudoers, ved hjelp av standard redigeringsprogram på din maskin, som Vim på min. Scroll down to the section where you see the following text: Bla ned til den delen hvor du se følgende tekst:
root ALL=(ALL) ALL root ALL = (ALL) ALL
The breakup of this sudo configuration syntax goes like this. Oppløsningen av sudo-konfigurasjon syntaks går som dette. You first define the 'user' for which you want to setup sudo. Du først definere 'user' som du ønsker å konfigurere sudo. Then comes the 'hostname' where the command is allowed to run. Så kommer "vertsnavnet" der kommandoen er tillatt å kjøre. This could be one specific hostname or “ALL” as in the example above. Dette kan være en bestemt vertsnavnet eller "ALLE" som i eksempelet ovenfor. And last is the 'command' for which you want to give the 'user' administrative privilege. Og sist er "kommandoen" som du ønsker å gi 'user' administrative privilegier.
Back to the configuration. Tilbake til konfigurasjonen. In Vim scroll down to the line shown above and hit the letter o on your keyboard to add a new line. I Vim bla ned til linjen vist ovenfor og trykk på bokstaven o på tastaturet for å legge til en ny linje. Now add the following text, replacing calvin with your own username: Nå kan du legge til følgende tekst, erstatter Calvin med ditt eget brukernavn:
calvin ALL=(ALL) ALL Calvin ALL = (ALL) ALL
Save and exit the file using the following key combination: Lagre og lukke filen ved hjelp av følgende tastekombinasjon:
ESC :wq ESC: WQ
Hit the Return (enter) key to apply these instructions. Hit the Return (inn) for å søke disse instruksjonene. We have now given the user 'calvin' all administrative privileges using sudo. Vi har nå gitt brukeren "Calvin" alle administratorrettigheter å bruke sudo. Open a new terminal window and log in as the user that you granted sudo privileges to. Åpne en ny terminal vindu og logg på som brukeren du gitt sudo privilegier til. Let's test whether the new permissions have been setup correctly by restarting the Apache web server as user 'calvin': La oss teste om de nye tillatelsene har vært setup riktig ved å starte Apache web server som bruker 'Calvin':
# sudo /etc/init.d/httpd restart Sudo / etc / init.d / httpd restart
Password: Passord:
Stopping httpd: [ OK ] Stoppe httpd: [OK]
Starting httpd: [ OK ] Starter httpd: [OK]
The system will now prompt you for a password. Systemet vil nå be deg om et passord. Enter the password for your username. Skriv inn passord for ditt brukernavn. And voila! Og voila! The Apache web server should now restart. Apache web server skal nå starte. You can use this for any other administrative task. Du kan bruke dette for noen andre administrative oppgaver. Granting complete privileges to a user may not always be the best of ideas. Gi fullstendige rettighetene til en bruker kan ikke alltid være det beste av ideer. So you can limit the user to a few command with administrative privileges. Så du kan begrense brukeren til noen kommando med administratorrettigheter. Let's say you want the user 'calvin' to be allowed to only restart the Apache web server. La oss si at du vil at brukeren "Calvin" for å få lov til bare å starte Apache web server. Open the sudo configuration file using the visudo command and edit the line you entered earlier to look like this: Åpne sudo konfigurasjonsfil bruker visudo kommandoen og redigere linjen du skrev inn tidligere for å se slik ut:
calvin ALL=(ALL) /etc/init.d/httpd restart Calvin ALL = (ALL) / etc / init.d / httpd restart
Save and exit the file. Lagre og lukke filen. Log into the terminal as the user 'calvin'. Logg inn på terminalen som brukeren "Calvin". Now try restarting Apache with sudo: Nå bør du starte Apache med sudo:
# sudo /etc/init.d/httpd restart Sudo / etc / init.d / httpd restart
Password: Passord:
Stopping httpd: [ OK ] Stoppe httpd: [OK]
Starting httpd: [ OK ] Starter httpd: [OK]
Great. Flott. It works. Det fungerer. Now try stopping the web server: Nå prøver stoppe webserveren:
# sudo /etc/init.d/httpd stop Sudo / etc / init.d / httpd stopp
Password: Passord:
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. Så som du kan se, kan brukeren "Calvin" bare gjøre det vi tillate ham å gjøre, ingenting mer. You can add multiple commands in the sudoers file separated by commas. Du kan legge til flere kommandoer i sudoers filen atskilt med komma. So if you want to allow 'calvin' the permission to stop and restart the web server your configuration would read like this: Så hvis du vil tillate "Calvin 'tillatelse til å stoppe og starte web server konfigurasjonen vil lese som dette:
calvin ALL=(ALL) /etc/init.d/httpd restart,/etc/init.d/httpd stop Calvin ALL = (ALL) / etc / init.d / httpd start, / etc / init.d / httpd stopp
Now try stopping the web server, and it should work: Nå kan du prøve å stoppe web-serveren, og det skal fungere:
# sudo /etc/init.d/httpd stop Sudo / etc / init.d / httpd stopp
Password: Passord:
Stopping httpd: [ OK ] Stoppe 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. En annen funksjon i sudo som er ganske nyttig, spesielt hvis du må utføre en administrativ oppgave bruker et shell script, er å sette sudo privilegium uten å bli spurt om passord. 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. Husk at det ikke kan være lurt å gjøre dette på en produksjon maskin ved hjelp av et brukernavn som deles, fordi hvis passordet til ditt brukernavn faller i gale hender kan stave problemer. So use this feature with caution. Så bruk denne funksjonen med forsiktighet.
Open the sudoers file and edit the line you entered earlier to look like this: Åpne sudoers filen og endre linjen du skrev inn tidligere for å se slik ut:
calvin ALL=(ALL) /etc/init.d/httpd restart NOPASSWD: ALL 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. Den siste delen av konfigureringen instruerer sudo å ikke be om eller forvente et passord, og tillater brukeren å utføre kommandoen som er tilordnet den med administratorrettigheter. Save the file and exit from your text editor and try restart Apache: Lagre filen og avslutt fra din tekst editor og prøv hvile Apache:
# sudo /etc/init.d/httpd restart Sudo / etc / init.d / httpd restart
Stopping httpd: [ OK ] Stoppe httpd: [OK]
Starting httpd: [ OK ] Starter httpd: [OK]
There is a lot more customization that can be done to the sudo configuration file. Det er mye mer tilpasning som kan gjøres til sudo konfigurasjonsfilen. We have just looked at a small segment of it. Vi har nettopp sett på en liten del av det. However, this ought to give you a start. Men dette burde gi deg en start. Again, please use it with caution. Igjen må du bruke det med forsiktighet.























2 Responses 2 Svar
Stay in touch with the conversation, subscribe to the Holde kontakten med samtalen, abonnere på RSS feed for comments on this post RSS feed for kommentarer til dette innlegget . .
Continuing the Discussion Fortsetter Discussion