web-dev-qa-db-ja.com

visudoを使用してsudoersファイルを直接変更する代わりに、/ etc / sudoers.d /にローカルコンテンツを追加する

/etc/sudoers.d/のいくつかの例と詳細な説明を教えてください

私はいくつかのグループにSudoにいくつかのコマンドを許可しますが、適切な方法で、マルチユーザーマシンのUbuntuセキュリティモデルに不必要な抜け穴を作らないようにします。

古代では、いくつかの単純なsudoersのカスタマイズを行っていましたが、どうやら今では/etc/sudoers.d/がより適切な方法であり、よりよく理解したいと思います。

28
Pawel Debski

この質問 が示すように、/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ディレクティブはコメントではありませんSudo/etc/sudoers.dディレクトリ内のファイル( '〜'で終わらない、または '。'文字を含まない)を読み取り、解析する効果もあります。

$ 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.
#

/etc/sudoersとは異なり、/etc/sudoers.dの内容はシステムのアップグレード後も保持されるため、/etc/sudoersを変更するよりもそこにファイルを作成することをお勧めします。

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

https://help.ubuntu.com/community/Sudoers で説明されているように、visudonanoの代わりに別のエディターを使用する場合があることに注意してください。

役立つと思われるリンクをいくつか次に示します。

38
Pawel Debski