su

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Su and the translation is 100% complete.
Other languages:

su ( s ubstitute u ser) コマンドは、システム上の他のユーザの権限を利用するために使うことができます。

このコマンドは util-linux パッケージによって提供され、これはデフォルトで有効化された su USE フラグ を持っています。su コマンドは sys-apps/shadow でも取得可能で、これも su USE フラグを持っています。これらのコマンドの両方を同時にインストールすることは避けてください。

注意

ユーザ root にアクセスするための su の使用は、呼び出しているユーザがユーザグループ wheel のメンバである場合のみ許可されます。

次の例では、ユーザ john がユーザグループ wheel に追加されます。

root # usermod -aG wheel john

使い方

user $ su --help
Usage:
 su [options] [-] [<user> [<argument>...]]
 
Change the effective user ID and group ID to that of <user>.
A mere - implies -l.  If <user> is not given, root is assumed.
 
Options:
 -m, -p, --preserve-environment      do not reset environment variables
 -w, --whitelist-environment <list>  don't reset specified variables
 
 -g, --group <group>             specify the primary group
 -G, --supp-group <group>        specify a supplemental group
 
 -, -l, --login                  make the shell a login shell
 -c, --command <command>         pass a single command to the shell with -c
 --session-command <command>     pass a single command to the shell with -c
                                   and do not create a new session
 -f, --fast                      pass -f to the shell (for csh or tcsh)
 -s, --shell <shell>             run <shell> if /etc/shells allows it
 -P, --pty                       create a new pseudo-terminal
 
 -h, --help                      display this help
 -V, --version                   display version
 
For more details see su(1).

root 権限を利用する

su はデフォルトでは root としてコマンドを実行します。ユーザ名を指定しないと su は root 権限を求めるので、以下のコマンドは root として実行され、システムを停止するでしょう:

user $ su -c 'shutdown -h now'
ヒント
-c オプションに続くコマンドはシングルクォートまたはダブルクォートでくくるのがベストプラクティスです。

他のユーザの権限を利用する

root 以外のユーザを su コマンドに指定することもできます。以下の例はコマンド echo をユーザ larry として実行します:

user $ su -c 'echo "Moo to the Gentoo Wiki reader out there!"' larry

関連項目

  • doas — provides a way to perform commands as another user.
  • sudo — 特権の昇格をシンプル・安全に管理します。
Retrieved from " /wiki/Su/ja&oldid=1403197 "