An introduction to the sudo command and configuration file Ievads sudo komandu un konfigurācijas failu

by Sukrit Dhandhania on December 29, 2008 ar Sukrit Dhandhania 2008 Decembris 29,

Linux

Ubuntu Linux users may be familiar with using the “sudo” command in Linux. Ubuntu Linux lietotāji var jāzina, izmantojot "sudo" komandu 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. Tas ir ļoti noderīgs līdzeklis Linux, kas ļauj ar Linux mašīna administrators piešķir "root" privilēģijas noteiktam lietotājam vai lietotāju grupai. It can also be configured so that this privilege is limited to one or more commands. To arī var konfigurēt tā, ka šīs tiesības ir tikai viena vai vairākas komandas. 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 komanda, piemēram, ir nolēmusi bloķēt root lietotājam pieteikties pēc noklusējuma, un tā vietā ļauj lietotājiem izmantot sudo, lai veiktu administratīvos uzdevumus. So if you are using Ubuntu Linux, sudo privileges have been setup so that you have full “root” privileges. Tātad, ja jūs lietojat Ubuntu Linux, sudo privilēģijas ir setup, lai jums būtu pilnīga "root" tiesībām. Let's take a closer look at setting up and configuring sudo privileges on your machine. Let's to tuvāk apskatīt izveide un konfigurēšana sudo privilēģijas uz jūsu datora. Before proceeding please note that you should not try the following on a production server. Pirms turpināt, lūdzu, ņemiet vērā, ka jums nevajadzētu mēģināt sekojošo ražošanas serveri. 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. Lūdzu, izmēģiniet šajā apmācība par testa mašīna piemēriem un iepazīties ar sudo, pirms jūs to izmēģinātu uz ražošanas serveri. sudo is a very powerful tool and must be used with extreme caution. sudo ir ļoti spēcīgs līdzeklis un tie jāizmanto ārkārtīgi piesardzīgi.

To my knowledge the “sudo” package ships with all Linux distributions. Cik man zināms "sudo" paketes kuģi ar visiem Linux sadalēm. So I'll skip the installation and jump straight to the configuration. So I'll izlaist ierīkošana un lekt taisni uz konfigurācijā. For this tutorial I will use a Red Hat Linux machine. Šo pamācību es izmantošu Red Hat Linux mašīnas. Log into your Linux machine as root and run the following command on the command line: Ieejiet savā Linux mašīna kā root un palaist šādu komandu komandrindas:

# 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. Iepriekš minēto komandu atvērsies "sudo" konfigurāciju, kas ir / etc / sudoers, izmantojot noklusējuma redaktorā uz jūsu datora, kas ir Spars uz manējās. Scroll down to the section where you see the following text: Ritiniet uz leju līdz iedaļā, kur jūs redzat šādu tekstu:

root    ALL=(ALL) ALL root ALL = (ALL) ALL

The breakup of this sudo configuration syntax goes like this. Šīs sudo konfigurācijas sintakse sabrukuma iet kā šis. You first define the 'user' for which you want to setup sudo. Jums vispirms jādefinē "lietotājs", kuram jūs vēlaties setup sudo. Then comes the 'hostname' where the command is allowed to run. Tad seko "hostname", ja komanda ir atļauts palaist. This could be one specific hostname or “ALL” as in the example above. Tas varētu būt viens no specifiskajiem hostname vai "ALL", kā iepriekšējā piemērā. And last is the 'command' for which you want to give the 'user' administrative privilege. Un pēdējā ir "komanda", par ko vēlaties piešķirt "lietotājs" Administratīvās privilēģijas.

Back to the configuration. Atpakaļ uz konfigurācijā. In Vim scroll down to the line shown above and hit the letter o on your keyboard to add a new line. In Spars ritiniet uz leju līdz līniju norādīts iepriekš un nospiediet burtu o uz tastatūras, lai pievienotu jaunu līniju. Now add the following text, replacing calvin with your own username: Tagad Pievienot šādu tekstu aizstāj Calvin ar savu lietotāja vārds:

calvin ALL=(ALL) ALL Calvin ALL = (ALL) ALL

Save and exit the file using the following key combination: Saglabāt un izejas failu, izmantojot šādu taustiņu kombināciju:

ESC :wq ESC: WQ

Hit the Return (enter) key to apply these instructions. Hit return (ievadīt) taustiņu, lai piemērotu šos norādījumus. We have now given the user 'calvin' all administrative privileges using sudo. Mums tagad ir dota lietotājam "Calvin" visas administratīvās privilēģijas izmanto sudo. Open a new terminal window and log in as the user that you granted sudo privileges to. Atvērt jaunā termināla logu un piesakieties kā lietotājam, ka jums piešķir sudo privilēģijas. Let's test whether the new permissions have been setup correctly by restarting the Apache web server as user 'calvin': Let's pārbaudīt, vai jaunas atļaujas ir setup pareizi atsākšanas Apache Web serveri kā lietotāja "Calvin":

# sudo /etc/init.d/httpd restart # Sudo / etc / init.d / httpd restart
Password: Parole:
Stopping httpd:                                            [  OK  ] Apstāšanās httpd: [OK]
Starting httpd:                                            [  OK  ] Starting httpd: [OK]

The system will now prompt you for a password. Sistēma tagad parādīs paroli. Enter the password for your username. Ievadiet paroli lietotājvārdu. And voila! Un voila! The Apache web server should now restart. Apache Web serveri tagad ir atjaunota. You can use this for any other administrative task. Jūs varat izmantot jebkuru citu administratīvo uzdevumu. Granting complete privileges to a user may not always be the best of ideas. Piešķirot pilnīgu privilēģijas lietotājs var ne vienmēr ir labākais ideju. So you can limit the user to a few command with administrative privileges. Tātad, jūs varat ierobežot lietotāju dažas komandu ar administratora tiesībām. Let's say you want the user 'calvin' to be allowed to only restart the Apache web server. Let's say vēlaties lietotājam "Calvin", kas ir atļauta tikai restart Apache web serveri. Open the sudo configuration file using the visudo command and edit the line you entered earlier to look like this: Open sudo konfigurācijas failu, izmantojot visudo komandu un rediģēt līnija ievadījāt agrāk, lai izskatās šādi:

calvin ALL=(ALL) /etc/init.d/httpd restart Calvin ALL = (ALL) / etc / init.d / httpd restart

Save and exit the file. Saglabāt un izejas failu. Log into the terminal as the user 'calvin'. Ieiet termināls kā lietotājs "Calvin". Now try restarting Apache with sudo: Tagad mēģināt atsākt Apache ar sudo:

# sudo /etc/init.d/httpd restart # Sudo / etc / init.d / httpd restart
Password: Parole:
Stopping httpd: [ OK ] Apstāšanās httpd: [OK]
Starting httpd: [ OK ] Starting httpd: [OK]

Great. Lielisks. It works. Tā darbojas. Now try stopping the web server: Tagad mēģiniet apstāšanās web serveris:

# sudo /etc/init.d/httpd stop # Sudo / etc / init.d / httpd stop
Password: Parole:
Sorry, user calvin is not allowed to execute '/etc/init.d/httpd stop' as root on commons. Atvainojiet, lietotājs Calvin nav atļauts execute '/ etc / init.d / httpd pieturas ", kā root no koptelpas.

So as you can see, the user 'calvin' can only do what we allow him to do, nothing more. Lai kā jūs varat redzēt, lietotājs "Calvin" var darīt tikai to, kas mums ļauj viņam to darīt, nekas vairāk. You can add multiple commands in the sudoers file separated by commas. Jūs varat pievienot vairākas komandas sudoers failā atdalīti ar komatiem. So if you want to allow 'calvin' the permission to stop and restart the web server your configuration would read like this: Tātad, ja jūs vēlaties, lai ļautu "Calvin" atļauju pārtraukt un atsākt web servera konfigurācijas varētu lasīt šādi:

calvin ALL=(ALL) /etc/init.d/httpd restart,/etc/init.d/httpd stop Calvin ALL = (ALL) / etc / init.d / httpd restart, / etc / init.d / httpd stop

Now try stopping the web server, and it should work: Tagad mēģiniet apstāšanās web servera, un tai vajadzētu strādāt:

# sudo /etc/init.d/httpd stop # Sudo / etc / init.d / httpd stop
Password: Parole:
Stopping httpd: [ OK ] Apstāšanās 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. Vēl viens sudo funkciju, kas ir diezgan noderīgs, jo īpaši, ja Jums nepieciešams veikt pārvaldes uzdevumu, izmantojot shell skripts, dibina sudo privilēģija bez pamudināja uz paroli. 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. Atcerieties, ka nav ieteicams to darīt ar ražošanas iekārtu, izmantojot lietotājvārdu, kas tiek dalīta, jo, ja jūsu lietotājvārds parole iekristu nepareizajās rokās, to var izskaidrot problēmas. So use this feature with caution. Lai izmantotu šo funkciju uzmanīgi.

Open the sudoers file and edit the line you entered earlier to look like this: Open sudoers failu un rediģēt līnija ievadījāt agrāk, lai izskatās šādi:

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. Pēdējo daļu konfigurācija uzdod sudo ne vaicāt, vai gaidīt paroli, un ļauj lietotājam izpildīt komandu, kas tam piešķirta ar administratīvajām tiesībām. Save the file and exit from your text editor and try restart Apache: Saglabājiet failu un izietu no teksta redaktora un mēģiniet restart Apache:

# sudo /etc/init.d/httpd restart # Sudo / etc / init.d / httpd restart
Stopping httpd: [ OK ] Apstāšanās httpd: [OK]
Starting httpd: [ OK ] Starting httpd: [OK]

There is a lot more customization that can be done to the sudo configuration file. Ir daudz pielāgošanu, ko var darīt, lai sudo konfigurācijas failu. We have just looked at a small segment of it. Mums ir vienkārši skatījās uz nelielu segmentu no tā. However, this ought to give you a start. Tomēr tas būtu jums sākt. Again, please use it with caution. Vēlreiz, lūdzu, izmantojiet to uzmanīgi.

Related Posts: Related Posts:
  • How to stop Ubuntu from asking for your sudo password Kā pārtraukt Ubuntu lūgt jūsu sudo parole
  • How to enable the root user account in Ubuntu Linux Kā lai root lietotāja kontu Ubuntu Linux
  • How to see a detailed history of the commands run in Linux Kā lai redzētu detalizētu vēsturi komandas palaist Linux
  • How to change the default web browser in Ubuntu Kā nomainīt noklusējuma Web pārlūku Ubuntu
  • How to install, setup and use Avant Window Navigator (Awn) in Ubuntu Feisty Kā uzstādīt, uzstādīšanas un lietošanas Avant Window Navigator (Awn) in Ubuntu Feisty
  • Get Simple Help tutorials just like this one in your email inbox every day - for free! Get Simple Palīdzība konsultācijas tāpat kā šo vienu savā e-pastā ik dienas - bez maksas! Just enter your email address below: Vienkārši ievadiet savu e-pasta adresi:

    You can always opt out of this email subscription at any time. Jūs vienmēr varat atteikties no šīs e-pasta abonementu jebkurā laikā.

    { 2 trackbacks } (2 trackbacks)

    Daily Digest for 2009-01-02 Daily Digest uz 2009/01/02
    01.02.09 at 4:03 pm 01.02.09 at 4:03
    Outrora, eu » Blog Archive » Links dos dias January 6th a January 12th Outrora, eu »Blog Archive» Saites dos dias 6 janvāris janvāris 12
    01.12.09 at 9:06 am 01.12.09 at 9:06

    { 0 comments… (0 comments ... add one now pievienot vienu tagad } )

    Leave a Comment Leave 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> Jūs varat izmantot šos HTML tagus un atribūtus: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>