Sudo/ja

sudoコマンドは特権の昇格をシンプル・安全に管理します. たとえば一般ユーザーが特定（もしくはすべて）のコマンドをrootや他のユーザーで（パスワードなしも含め）実行できるようにします.

ユーザーに特権の必要な操作を許可したいがrootは渡したくない、という時にはsudoを使うとよいでしょう. sudoは誰が何をすることができるかを制御できます. それではこの素敵なツールについて簡単に紹介します.

Granting Permissions
The  package allows the system administrator to grant permission to other users to execute one or more applications they would normally have no right to. Unlike using the setuid bit on these applications  gives a more fine-grained control on who can execute a certain command and when.

With  you can make a clear list who can execute a certain application. If you would set the setuid bit, any user would be able to run this application (or any user of a certain group, depending on the permissions used). You can (and probably even should) require the user to provide a password when he wants to execute the application.

Logging Activity
One additional advantage of  is that it can log any attempt (successful or not) to run an application. This is very useful if you want to track who made that one fatal mistake that took you 10 hours to fix :)

sudoの設定
の設定はに書かれています. このファイルを や やその他のエディタで編集してはいけません. 代わりに を使うようにしてください.

このツールは二人以上の管理者が同時にこのファイルを編集することを防ぎ、ファイルのパーミッションを保ち、大失敗をしないように文法チェックを行います.

About this Guide
This guide is meant as a quick introduction. The  package is a lot more powerful than what is described in this guide. It has special features for editing files as a different user, running from within a script (so it can background, read the password from standard in instead of the keyboard, ...), etc.

Please read the  and   manual pages for more information.

Basic Syntax
の最も難解な部分がの構文です. 基本的な構文を示します.

/etc/sudoersの基本的な構文

この構文では、"host"からログインしている"user"というユーザーは"commands"に上げられたコマンドをrootとして実行してもよい、ということを に示します. "swift"がlocalhostでログインしていたら の実行を許可する、といった現実的な例を考えるとわかりやすいでしょう.

/etc/sudoersの現実的な例

ユーザー名の代わりにグループ名を使うこともできます. この場合はグループ名の頭に をつけてください. グループのメンバーに の実行を許可する場合はこのように書きます.

wheelグループのメンバーにemergeの実行を許可する

コマンドごとに行を増やす代わりに、一行に複数のコマンドを書くこともできます. 例えば先ほどのユーザーに だけでなく と の実行も許可する場合はこう書きます.

複数のコマンドを指定する

You can also specify a precise command and not only the tool itself. This is useful to restrict the use of a certain tool to a specified set of command options. The  tool allows shell-style wildcards (AKA meta or glob characters) to be used in pathnames as well as command line arguments in the sudoers file. Note that these are not regular expressions.

Let us put this to the test:

が要求するパスワードはユーザー自身のパスワードです. この手順を踏むことで、うっかりログインしたまま席を離れてしまった時に不正利用されないようにします.

なお は を変更しません. で実行するコマンドはあなたの環境から実行されます. このため、などに置かれたツールを実行したい時は次のように完全なパスを に渡す必要があります.

Basic Syntax with LDAP
The following use flag is needed for the LDAP support.

When using sudo with LDAP, sudo will read configuration from LDAP Server as well. So you will need to edit two files.

{{FileBox|filename=/etc/ldap.conf.sudo|title=Please chmod 400 when done|1= host ldap.example.com port 389 base dc=example,dc=com uri ldap://ldap.example.com/ ldap_version 3 sudoers_base ou=SUDOers,dc=example,dc=com bind_policy soft }}
 * 1) See ldap.conf(5) and README.LDAP for details
 * 2) This file should only be readable by root
 * 1) supported directives: host, port, ssl, ldap_version
 * 2) uri, binddn, bindpw, sudoers_base, sudoers_debug
 * 3) tls_{checkpeer,cacertfile,cacertdir,randfile,ciphers,cert,key
 * 1) uri ldapi://%2fvar%2frun%2fopenldap%2fslapd.sock
 * 1) ssl start_tls
 * 1) sudoers_debug 2

Also you will need to add in the following LDAP Entry for Sudo.

The configuration on the sudoer on LDAP are similar to files with some different. Please read more about Sudo with LDAP on the link below.

alias (to make a good distinction between aliases and non-aliases it is recommended to use capital letters for aliases). As you might undoubtedly have guessed, the  alias is an alias to all possible settings.

A sample use of the  alias to allow any user to execute the   command if he is logged on locally is:

Another example is to allow the user  to execute the   command as root, regardless of where he is logged in from:

More interesting is to define a set of users who can run software administrative applications (such as  and   ) on the system and a group of administrators who can change the password of any user, except root!

Non-Root Execution
It is also possible to have a user run an application as a different, non-root user. This can be very interesting if you run applications as a different user (for instance  for the web server) and want to allow certain users to perform administrative steps as that user (like killing zombie processes).

Inside you list the user(s) in between   and   before the command listing:

For instance, to allow  to run the   tool as the   or   user:

With this set, the user can run  to select the user he wants to run the application as:

You can set an alias for the user to run an application as using the  directive. Its use is identical to the other  directives we have seen before.

Passwords and Default Settings
By default,  asks the user to identify himself using his own password. Once a password is entered,  remembers it for 5 minutes, allowing the user to focus on his tasks and not repeatedly re-entering his password.

Of course, this behavior can be changed: you can set the  directive in  to change the default behavior for a user.

For instance, to change the default 5 minutes to 0 (never remember):

A setting of  would remember the password indefinitely (until the system reboots).

A different setting would be to require the password of the user that the command should be run as and not the users' personal password. This is accomplished using. In the following example we also set the number of retries (how many times the user can re-enter a password before  fails) to   instead of the default 3:

Another interesting feature is to keep the  variable set so that you can execute graphical tools:

You can change dozens of default settings using the  directive. Fire up the  manual page and search for.

If you however want to allow a user to run a certain set of commands without providing any password whatsoever, you need to start the commands with , like so:

Listing Privileges
To inform yourself what your capabilities are, run  :

If you have any command in that does not require you to enter a password, it will not require a password to list the entries either. Otherwise you might be asked for your password if it isn't remembered.

Prolonging the Password Timeout
By default, if a user has entered his password to authenticate himself to , it is remembered for 5 minutes. If the user wants to prolong this period, he can run  to reset the time stamp so that it will take another 5 minutes before   asks for the password again.

The inverse is to kill the time stamp using.

Bash Completion
Users that want bash completion with sudo need to run this once.

Zshell Completion
Users that want zsh completion for sudo can set the following in and  respectively

With the above change, all commands in the, and  locations will be available to the shell for completion when the command is prefaced with 'sudo'.