Debianのsudoの設定

2011.10.27 1:21
解決手段としては一般ユーザーからsudoコマンドを使って作業を行うようにする方法がある。
一般的にはrootで作業を行う場合は
 $ su -
パスワード:
# vi abc.txt
とするが、sudoコマンドを使うようにすれば、
$ sudo vi abc.txt
[sudo] password for user:
というように、root権限で行いたい作業のコマンドの後ろにsudoをつけ、一般ユーザーのパスワードを使うことでrootユーザーと同じ作業を行うことが出来る。一般ユーザーにsudoコマンドを使う権限を与えるにはrootユーザーからvisudoコマンドを使って、sudoコマンドの設定ファイルである/etc/sudoersを編集する。
# visudo
Debian Lennyの場合、標準でnanoエディタが起動する。
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#

Defaults        env_reset

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL) ALL
# Uncomment to allow members of group sudo to not need a password
# (Note that later entries override this, so you might need to move
# it further down)
# %sudo ALL=NOPASSWD: ALL
「root    ALL=(ALL) ALL」と言う風になっている文章の下に、権限を与えたいユーザーを加える。書式は以下の通り。
ユーザ ホスト=(権限) コマンド
ユーザには、sudo権限を与えたいユーザー名を記述する。今回の例ではsaoriにする。
ホストは使用したいホストを書く。一般的にはALLと書く様です。
権限には「誰の権限でコマンドを実行したいか」を書くようです(例:(root))が、ここも一般的にはALLにすることが多い様です。コマンドにはsudoで扱えるコマンドを絶対パスで指定します。複数指定する場合は,(カンマ)で区切ります。一般的には、以下のような設定にすることが多い様です。
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#

Defaults        env_reset

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL) ALL
saori        ALL=(ALL) ALL
# Uncomment to allow members of group sudo to not need a password
# (Note that later entries override this, so you might need to move
# it further down)
# %sudo ALL=NOPASSWD: ALL
上記は、単純にsaoriユーザーにsudoコマンドを使えば、全てのコマンドをスーパーユーザ権限で使えるように設定しています。









プロフィール



  • Name :: 山上オサム ♂(39)
  • Hobby :: 武術
  • Work :: Web Designer