sudo
パーミッション
書き方
sudo [cmd]命令一つを別の利用者、既定では root として実行します。sudo cmd > file の > は自分のシェルで開かれるので root 所有のファイルでは失敗し、そこでは tee を使います。
よく使うオプション
| オプション | 意味 |
|---|---|
| -u | Run as another user instead of root |
| -i | Start a login shell with that user environment |
| -s | Start a shell but keep your own environment |
| -E | Keep your environment variables, if the policy allows it |
| -k | Forget the cached password right now |
| -l | List what you are allowed to run |
| -v | Refresh the timestamp without running anything |
例
sudo -u postgres psqlRuns the client as the postgres user.
sudo -iA root login shell, with root PATH and environment.
echo text | sudo tee -a /etc/hostsRedirection needs tee, because > runs as you.
数字モードと記号モードは同じものを指します。755 と u=rwx,go=rx は同じ意味です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. sudo は何をしますか。
命令一つを別の利用者、既定では root として実行します。sudo cmd > file の > は自分のシェルで開かれるので root 所有のファイルでは失敗し、そこでは tee を使います。
Q. どう打ちますか。
sudo [cmd] — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは7個です。全部は man sudo にあります。このコマンドはパーミッションの仲間です。
関連するコマンド
man ページ: man sudo