добавление локального содержимого в /etc/sudoers.d/ вместо прямого изменения файла sudoers с помощью visudo

Можете ли вы направить меня на некоторые примеры и более подробную инструкцию по /etc/sudoers.d/

Я хотел бы дать некоторое групповое разрешение для sudo некоторых команд, но надлежащим образом не для создания ненужных лазеек в модели безопасности Ubuntu на многопользовательской машине.

В древние времена я делал некоторые простые настройки sudoers, но, видимо, теперь /etc/sudoers.d/ является более правильным способом, и я 'd хотел бы лучше понять это.

13
задан 30 June 2017 в 20:01

3 ответа

Похоже, никто не осмеливался, поэтому я провел собственное исследование. Вот результаты.

Как эта нить https://superuser.com/questions/869144/why-does-the-system-have-etc-sudoers-d-how-should-i-edit -it подчеркивает, что / etc / sudoers - это системный файл конфигурации, который изменяется при обновлении системы и очень хрупкий для неправильных изменений. То есть вы можете потерять системный доступ или не загрузиться с неправильными изменениями.

$ sudo cat /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#

(... some other content ...)

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

Вопреки тому, что вы думаете, что директива #includedir не является комментарием. Он действителен и включает в себя все файлы в каталоге /etc/sudoers.d.

Содержимое этого каталога выживает при обновлении системы, а также в sudo строго сказано:

Ошибки в файле не вызвало ошибку sudo. Правила доступа выглядят менее строгими.

Поэтому менее вероятно, что вы принесете систему своими ошибками.

$ ls -l /etc/sud*
-r--r----- 1 root root  755 sty 20 17:03 /etc/sudoers

/etc/sudoers.d:
total 7
-r--r----- 1 root root 958 mar 30  2016 README
$ sudo cat /etc/sudoers.d/README
#
# As of Debian version 1.7.2p1-1, the default /etc/sudoers file created on
# installation of the package now includes the directive:
# 
#   #includedir /etc/sudoers.d
# 
# This will cause sudo to read and parse any files in the /etc/sudoers.d 
# directory that do not end in '~' or contain a '.' character.
# 
# Note that there must be at least one file in the sudoers.d directory (this
# one will do), and all files in this directory should be mode 0440.
# 
# Note also, that because sudoers contents can vary widely, no attempt is 
# made to add this directive to existing sudoers files on upgrade.  Feel free
# to add the above directive to the end of your /etc/sudoers file to enable 
# this functionality for existing installations if you wish!
#
# Finally, please note that using the visudo command is the recommended way
# to update sudoers content, since it protects against many failure modes.
# See the man page for visudo for more information.
#

Обратите внимание, что файлы в этом каталоге должны быть отредактированы командой visudo:

$ sudo visudo -f /etc/sudoers.d/veracrypt
  GNU nano 2.5.3        File: /etc/sudoers.d/veracrypt.tmp                      

# Users in the veracryptusers group are allowed to run veracrypt as root.
%veracryptusers ALL=(root) NOPASSWD:/usr/bin/veracrypt

Обратите внимание, что visudo может использовать разные редакторы для реальной задачи, как описано здесь: https://superuser.com/questions/869144/why-does-the-system-have -etc-sudoers-d-how-should-i-edit-it

Вот несколько ссылок, которые я нашел полезными:

https: // en .wikipedia.org / wiki / Sudo http://manpages.ubuntu.com/manpages/precise/man8/visudo.8.html https://ubuntuforums.org/showthread.php?t=1132821
9
ответ дан 22 May 2018 в 20:59
  • 1
    Неверно, что ошибки в файлах в /etc/sudoers.d не могут сбить sudo. Эти файлы объединены с /etc/sudoers. Те же правила применяются к этим файлам. – tobltobs 18 October 2017 в 19:52
  • 2
    Правильно, что вы МОЖЕТЕ привести систему к неправильному файлу, так как это МЕНЬ. #includedir - это не просто простая глупая конкатенация, в то время как в том числе происходит некоторая проверка, поэтому наиболее очевидные ошибки должны быть обнаружены и что вы можете легко восстановить. Однако будьте осторожны - вы всегда можете повредить себе острым ножом, поэтому обращайтесь с ним осторожно ;-) – Pawel Debski 23 October 2017 в 20:45
  • 3
    Я бы с удовольствием встретил парня, который думал, что #include в этом файле должен быть активным и не комментировать. Псих. – Richard Riley 24 January 2018 в 21:15

Похоже, никто не осмеливался, поэтому я провел собственное исследование. Вот результаты.

Как эта нить https://superuser.com/questions/869144/why-does-the-system-have-etc-sudoers-d-how-should-i-edit -it подчеркивает, что / etc / sudoers - это системный файл конфигурации, который изменяется при обновлении системы и очень хрупкий для неправильных изменений. То есть вы можете потерять системный доступ или не загрузиться с неправильными изменениями.

$ sudo cat /etc/sudoers # # This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # (... some other content ...) # See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d

Вопреки тому, что вы думаете, что директива #includedir не является комментарием. Он действителен и включает в себя все файлы в каталоге /etc/sudoers.d.

Содержимое этого каталога выживает при обновлении системы, а также в sudo строго сказано:

Ошибки в файле не вызвало ошибку sudo. Правила доступа выглядят менее строгими.

Поэтому менее вероятно, что вы принесете систему своими ошибками.

$ ls -l /etc/sud* -r--r----- 1 root root 755 sty 20 17:03 /etc/sudoers /etc/sudoers.d: total 7 -r--r----- 1 root root 958 mar 30 2016 README $ sudo cat /etc/sudoers.d/README # # As of Debian version 1.7.2p1-1, the default /etc/sudoers file created on # installation of the package now includes the directive: # # #includedir /etc/sudoers.d # # This will cause sudo to read and parse any files in the /etc/sudoers.d # directory that do not end in '~' or contain a '.' character. # # Note that there must be at least one file in the sudoers.d directory (this # one will do), and all files in this directory should be mode 0440. # # Note also, that because sudoers contents can vary widely, no attempt is # made to add this directive to existing sudoers files on upgrade. Feel free # to add the above directive to the end of your /etc/sudoers file to enable # this functionality for existing installations if you wish! # # Finally, please note that using the visudo command is the recommended way # to update sudoers content, since it protects against many failure modes. # See the man page for visudo for more information. #

Обратите внимание, что файлы в этом каталоге должны быть отредактированы командой visudo:

$ sudo visudo -f /etc/sudoers.d/veracrypt GNU nano 2.5.3 File: /etc/sudoers.d/veracrypt.tmp # Users in the veracryptusers group are allowed to run veracrypt as root. %veracryptusers ALL=(root) NOPASSWD:/usr/bin/veracrypt

Обратите внимание, что visudo может использовать разные редакторы для реальной задачи, как описано здесь: https://superuser.com/questions/869144/why-does-the-system-have -etc-sudoers-d-how-should-i-edit-it

Вот несколько ссылок, которые я нашел полезными:

https: // en .wikipedia.org / wiki / Sudo http://manpages.ubuntu.com/manpages/precise/man8/visudo.8.html https://ubuntuforums.org/showthread.php?t=1132821
13
ответ дан 18 July 2018 в 10:52

Похоже, никто не осмеливался, поэтому я провел собственное исследование. Вот результаты.

Как эта нить https://superuser.com/questions/869144/why-does-the-system-have-etc-sudoers-d-how-should-i-edit -it подчеркивает, что / etc / sudoers - это системный файл конфигурации, который изменяется при обновлении системы и очень хрупкий для неправильных изменений. То есть вы можете потерять системный доступ или не загрузиться с неправильными изменениями.

$ sudo cat /etc/sudoers # # This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # (... some other content ...) # See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d

Вопреки тому, что вы думаете, что директива #includedir не является комментарием. Он действителен и включает в себя все файлы в каталоге /etc/sudoers.d.

Содержимое этого каталога выживает при обновлении системы, а также в sudo строго сказано:

Ошибки в файле не вызвало ошибку sudo. Правила доступа выглядят менее строгими.

Поэтому менее вероятно, что вы принесете систему своими ошибками.

$ ls -l /etc/sud* -r--r----- 1 root root 755 sty 20 17:03 /etc/sudoers /etc/sudoers.d: total 7 -r--r----- 1 root root 958 mar 30 2016 README $ sudo cat /etc/sudoers.d/README # # As of Debian version 1.7.2p1-1, the default /etc/sudoers file created on # installation of the package now includes the directive: # # #includedir /etc/sudoers.d # # This will cause sudo to read and parse any files in the /etc/sudoers.d # directory that do not end in '~' or contain a '.' character. # # Note that there must be at least one file in the sudoers.d directory (this # one will do), and all files in this directory should be mode 0440. # # Note also, that because sudoers contents can vary widely, no attempt is # made to add this directive to existing sudoers files on upgrade. Feel free # to add the above directive to the end of your /etc/sudoers file to enable # this functionality for existing installations if you wish! # # Finally, please note that using the visudo command is the recommended way # to update sudoers content, since it protects against many failure modes. # See the man page for visudo for more information. #

Обратите внимание, что файлы в этом каталоге должны быть отредактированы командой visudo:

$ sudo visudo -f /etc/sudoers.d/veracrypt GNU nano 2.5.3 File: /etc/sudoers.d/veracrypt.tmp # Users in the veracryptusers group are allowed to run veracrypt as root. %veracryptusers ALL=(root) NOPASSWD:/usr/bin/veracrypt

Обратите внимание, что visudo может использовать разные редакторы для реальной задачи, как описано здесь: https://superuser.com/questions/869144/why-does-the-system-have -etc-sudoers-d-how-should-i-edit-it

Вот несколько ссылок, которые я нашел полезными:

https: // en .wikipedia.org / wiki / Sudo http://manpages.ubuntu.com/manpages/precise/man8/visudo.8.html https://ubuntuforums.org/showthread.php?t=1132821
13
ответ дан 24 July 2018 в 19:40

Другие вопросы по тегам:

Похожие вопросы: