Skip to content Перейти до змісту


An introduction to the sudo command and configuration file Введення в команді Суду і конфігураційний файл

Linux

Ubuntu Linux users may be familiar with using the “sudo” command in Linux. Ubuntu Linux користувачі можуть бути знайомі з використанням "Суду" команди в 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. Це дуже корисна функція в Linux, що дозволяє адміністратору машині Linux надати "кореневого" привілеї для конкретного користувача або групи користувачів. It can also be configured so that this privilege is limited to one or more commands. Вона також може бути налаштований так, що цей привілей обмежується однієї або декількох команд. 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, наприклад, вирішили блокувати кореневого користувача від входу в систему за замовчуванням, і замість того щоб користувачі могли використовувати Суду для виконання адміністративних задач. So if you are using Ubuntu Linux, sudo privileges have been setup so that you have full “root” privileges. Так що якщо ви використовуєте Ubuntu Linux, Sudo привілеї були настройку, щоб у вас є повна "корінь" привілеїв. Let's take a closer look at setting up and configuring sudo privileges on your machine. Давайте уважніше розглянемо установку і настройку Суду привілеїв на комп'ютері. Before proceeding please note that you should not try the following on a production 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. Спробуйте з прикладів у цьому підручнику на тестовій машині і познайомитися з Судом, перш ніж намагатися його на сервер. sudo is a very powerful tool and must be used with extreme caution. Суду є дуже потужним інструментом і повинно використовуватися з крайньою обережністю.

To my knowledge the “sudo” package ships with all Linux distributions. Наскільки мені відомо, "Суду" пакет суду у всіх дистрибутивах Linux. So I'll skip the installation and jump straight to the configuration. Ось я і буду показувати установку і перейти прямо до конфігурації. For this tutorial I will use a Red Hat Linux machine. Для цього уроку я буду використовувати Red Hat Linux машині. Log into your Linux machine as root and run the following command on the command line: Увійдіть в свою машину Linux як супер-і запустіть наступну команду в командному рядку:

# 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. Ця команда буде відкрити "Суду" конфігурації, який знаходиться в / ETC / sudoers, використовуючи редактор за замовчуванням на вашій машині, яка Vim на мій. Scroll down to the section where you see the following text: Перейдіть в розділ, де ви побачите наступний текст:

root    ALL=(ALL) ALL кореневих ALL = (ALL) ALL

The breakup of this sudo configuration syntax goes like this. Розпад цього Суду синтаксис конфігурації виглядає так. You first define the 'user' for which you want to setup sudo. Спочатку визначимо 'Користувачі', для якого ви хочете поставити Суду. Then comes the 'hostname' where the command is allowed to run. Потім настає 'ім'я хоста ", де команда зможуть вибрати. This could be one specific hostname or “ALL” as in the example above. Це може бути одне конкретне ім'я або "ВСЕ", як у наведеному вище прикладі. And last is the 'command' for which you want to give the 'user' administrative privilege. І останнє, це "команда", за якими ви хочете дати "користувач" адміністративних привілеїв.

Back to the configuration. Повернутися в конфігурацію. In Vim scroll down to the line shown above and hit the letter o on your keyboard to add a new line. У Vim Прокрутіть вниз до рядка показано вище та натисніть букву O на клавіатурі, щоб додати новий рядок. Now add the following text, replacing calvin with your own username: Тепер додайте наступний текст, замінивши Calvin з вашим власним Ім'я користувача:

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

Save and exit the file using the following key combination: Збережіть і закрийте файл, використовуючи наступні сполучення клавіш:

ESC :wq ESC: WQ

Hit the Return (enter) key to apply these instructions. Hit The Return (Enter), ключовим для застосування цих інструкцій. We have now given the user 'calvin' all administrative privileges using sudo. Ми тепер дають Calvin користувачів 'всі адміністративних привілеїв з допомогою Суду. 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': Давайте перевіримо нові дозволи були коректно налаштований шляхом перезавантаження сервера Apache Web Calvin як користувач ':

# sudo /etc/init.d/httpd restart # Sudo / і т.д. / init.d / HTTPD перезавантаження
Password: Пароль:
Stopping httpd:                                            [  OK  ] Зупинка HTTPD: [OK]
Starting httpd:                                            [  OK  ] Починаючи 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. Сервер Apache Web тепер перезавантажити. 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. Припустимо, ви хочете Calvin користувача ', щоб бути дозволено тільки перезапустити сервер Apache. Open the sudo configuration file using the visudo command and edit the line you entered earlier to look like this: Відкрийте конфігураційний файл Суду допомогою visudo команди і редагувати лінію ви вступили раніше, щоб виглядати наступним чином:

calvin ALL=(ALL) /etc/init.d/httpd restart Calvin ALL = (ALL) / і т.д. / init.d / HTTPD перезавантаження

Save and exit the file. Збережіть і закрийте файл. Log into the terminal as the user 'calvin'. Вхід в термінал як користувач 'Кальвіна. Now try restarting Apache with sudo: Тепер спробуйте перезапустити Apache з Судом:

# sudo /etc/init.d/httpd restart # Sudo / і т.д. / init.d / HTTPD перезавантаження
Password: Пароль:
Stopping httpd: [ OK ] Зупинка HTTPD: [OK]
Starting httpd: [ OK ] Починаючи HTTPD: [OK]

Great. Великий. It works. Це працює. Now try stopping the web server: Тепер спробуйте зупинити веб-сервер:

# sudo /etc/init.d/httpd stop # Sudo / і т.д. / init.d / HTTPD зупинка
Password: Пароль:
Sorry, user calvin is not allowed to execute '/etc/init.d/httpd stop' as root on commons. Вибачте, користувач Кальвін не дозволяється виконувати '/ і т.д. / init.d / HTTPD зупинки ", як про корінних громад.

So as you can see, the user 'calvin' can only do what we allow him to do, nothing more. Отже, як ви можете бачити, Calvin користувач "може робити тільки те, що ми дозволили йому це зробити, нічого більше. You can add multiple commands in the sudoers file separated by commas. Ви можете додати кілька команд у sudoers файлу, розділених комами. So if you want to allow 'calvin' the permission to stop and restart the web server your configuration would read like this: Так що якщо ви хочете, щоб дозволити 'Calvin' дозвіл, щоб зупинити і перезапустити сервер конфігурації буде виглядати приблизно так:

calvin ALL=(ALL) /etc/init.d/httpd restart,/etc/init.d/httpd stop Calvin ALL = (ALL) / і т.д. / init.d / HTTPD перезавантаження / і т.д. / init.d / HTTPD зупинка

Now try stopping the web server, and it should work: Тепер спробуйте зупинити веб-сервер, і воно має працювати:

# sudo /etc/init.d/httpd stop # Sudo / і т.д. / init.d / HTTPD зупинка
Password: Пароль:
Stopping httpd: [ OK ] Зупинка 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: Відкриття файлу sudoers і редагувати лінію ви вступили раніше, щоб виглядати наступним чином:

calvin ALL=(ALL) /etc/init.d/httpd restart NOPASSWD: ALL Calvin ALL = (ALL) / і т.д. / init.d / перезапуск NOPASSWD HTTPD: 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: Збережіть файл і вийдіть з текстового редактора і спробувати перезапустити Apache:

# sudo /etc/init.d/httpd restart # Sudo / і т.д. / init.d / HTTPD перезавантаження
Stopping httpd: [ OK ] Зупинка HTTPD: [OK]
Starting httpd: [ OK ] Починаючи 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. Знову ж таки, будь ласка, використовуйте його з обережністю.

Posted in Опубліковано в Linux Linux . .

Related Posts: Схожі повідомлення:

How to enable the root user account in Ubuntu Linux Як включити обліковий запис користувача root в Ubuntu Linux
How to stop Ubuntu from asking for your sudo password Як зупинити Ubuntu із запитами Суду пароля
How to see a detailed history of the commands run in Linux Як побачити детальну історію команд працюють в Linux
How to change the default web browser in Ubuntu Як змінити браузер за умовчанням в Ubuntu Мережі
How to play .rmvb files in Ubuntu Як грати. RMVB файлів в Ubuntu

2 Responses 2 Відповіді

Stay in touch with the conversation, subscribe to the Залишайтеся на зв'язку при розмові, підпишіться на RSS feed for comments on this post RSS-канал для коментарів на цю посаду . .

Continuing the Discussion Продовжуючи розмову

  1. Daily Digest for 2009-01-02 Щоденний дайджест за 2009-01-02 linked to this post on January 2, 2009 пов'язані на цю посаду 2 січня 2009

    [...] Jackie bookmarked a link on Delicious. [...] Джекі закладкою посилання на Delicious. An introduction to the sudo command and configuration file – Simple Help [...] Введення в команді Суду і конфігураційний файл - просто Допомога [...]

  2. Outrora, eu » Blog Archive » Links dos dias January 6th a January 12th Outrora ЄС »Blog Archive» Посилання Діаш душ 6 января 12 січня linked to this post on January 12, 2009 пов'язані на цю посаду 12 січня 2009

    [...] An introduction to the sudo command and configuration file – Simple Help – 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. [...] Введенні в команді Суду і конфігураційний файл - простий у допомоги - це дуже корисна функція в Linux, що дозволяє адміністратору машині Linux надати "кореневого" привілеї для конкретного користувача або групи користувачів. It can also be configured so that this privilege is limited to one or more commands. Вона також може бути налаштований так, що цей привілей обмежується однієї або декількох команд. [...] [...]



Some HTML is OK Деякі HTML нормально

or, reply to this post via або відповісти на цей пост через trackback Архів . .