Введение к команде sudo и конфигурация хранят

[[by]] Sukrit Dhandhania на 29-ое декабря 2008

Linux

Потребители Ubuntu Linux могут быть знакомы с использованием команды «sudo» в Linux. Будет очень полезной характеристикой в Linux позволяет администратору машины Linux к привилегированностям «корня» дара к определенным потребителю или группе в составе потребители. Его можно также установить TAK, CTO эта привилегированность будет ограничена к one or more командам. Команда Ubuntu, например, решала преградить потребителя корня от log on невыполнением обязательства и вместо позволить потребителей использовать sudo для того чтобы выполнить управленческие задачи. Так если вы используете Ubuntu Linux, то, привилегированности sudo были setup TAK, CTO вы будете иметь вполне привилегированности «корня». Препятствуйте нам принять более близкий взгляд на устанавливать - вверх и устанавливая привилегированности sudo на вашей машине. Перед продолжать пожалуйста примечание что вы не должны попытаться following на сервере продукции. Пожалуйста try out примеры в этой консультации на машине испытания и получите знакомо с sudo прежде чем вы пытаетесь оно вне на сервере продукции. sudo будет очень мощным инструментом и должно быть использовано с весьма предосторежением.

To my knowledge пакет «sudo» грузит с всеми распределениями Linux. Так я прыгну установка и поскачу прямо к конфигурации. Для этой консультации я буду использовать красную машину Linux шлема. Журнал в вашу побежали машину Linux как корень и, котор following команде на линии команды:

# visudo

Вышеуказанная команда раскроет конфигурацию «sudo», которой на /etc/sudoers, использующ редактора невыполнения обязательства на вашей машине, которая Vim на моих. Перечислите вплоть до раздел где вы видите following текст:

корень? ? ALL= (ВСЕ) ВСЕ

Breakup этого синтаксиса конфигурации sudo идет как это. Вы сперва определяете потребителя `' для вы хотите для того чтобы setup sudo. После этого приходит hostname `' где позволена команда побежать. Это было в состоянии быть один специфически hostname или «ВСЕ» как в примере выше. И последняя команда `' для вы хочет дать привилегированность потребителя `' управленческая.

Back to конфигурация. В Vim вплоть переченя до ударенная линия показанная выше и письму o на вашей клавиатуре для того чтобы добавить новую линию. Теперь добавьте following текст, заменяя ть calvin с вашим собственным username:

calvin ALL= (ВСЕ) ВСЕ

За исключением и выйдите архив использующ following ключевую комбинацию:

ESC: wq

Ударьте Возвращение (войдите) ключ для того чтобы приложить эти инструкции. Мы теперь давали calvin `потребителя' все управленческие привилегированности использующ 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.

Related Posts:
  • How to install, setup and use Avant Window Navigator (Awn) in Ubuntu Feisty
  • How to play .rmvb files in Ubuntu
  • How to setup Virtual Hosts in Apache
  • How to set the date on your Linux machine
  • How to use your Nokia N95 as a wireless Webcam
  • Get Simple Help tutorials just like this one in your email inbox every day - for free! Just enter your email address below:

    You can always opt out of this email subscription at any time.

    { 2 trackbacks }

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

    { 0 comments… add one now }

    Leave a 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>