Ubuntu sudo 1.8.16 命令详解


sudo 是 switch user do (切换用户处理) 的简写。

sudo 允许系统管理员, 让普通用户执行一些或全部 root 命令。

sudo 不仅减少了 root 用户的登录 管理时间, 还提高了安全性。

sudo 不是对 Shell 的简单代替, 可面向所有命令。

另请参阅: su

基本用法     详细用法

sudo su
			

基本语法

sudo -h | -K | -k | -V
 
sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]
 
sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command]
 
sudo [-AbEHknPS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p prompt] [-u user] [VAR=value] [-i|-s] [<command>]
 
sudo -e [-AknS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p prompt] [-u user] file ...
			

Options 选项

参数 EN 解释 中文翻译 备注
-A, --askpass use a helper program for password prompting 使用助手程序提示密码
-b, --background run command in the background 在后台运行命令
-C, --close-from=num close all file descriptors >= num 关闭 >= num 的所有文件描述符
-E, --preserve-env preserve user environment when running command 保留用户环境, 当运行命令时
-e, --edit edit files instead of running a command 编辑文件而非运行命令
-g, --group=group run command as the specified group name or ID 由指定组名或 ID 运行命令
-H, --set-home set HOME variable to target user's home dir 把 HOME 变量设为目标用户的主目录
-h, --help display help message and exit 显示帮助消息并退出
-h, --host=host run command on host (if supported by plugin) 在主机上运行命令 (若插件支持)
-i, --login

run login shell as the target user;

a command may also be specified

由目标用户运行登录 Shell;

也可指定命令

-K, --remove-timestamp remove timestamp file completely 完全移除时间戳文件
-k, --reset-timestamp invalidate timestamp file 使时间戳文件无效
-l, --list

list user's privileges or check a specific command;

use twice for longer format

列表用户的特权或校验特定命令;

使用两次为更长格式

-n, --non-interactive

non-interactive mode,

no prompts are used

非交互模式,

使用时不提示

-P, --preserve-groups preserve group vector instead of setting to target's 保留组向量,而非目标的设置
-p, --prompt=prompt use the specified password prompt 使用指定口令提示
-r, --role=role create SELinux security context with specified role 创建具有指定角色的 SELinux 安全上下文
-S, --stdin read password from standard input 从标准输入读取口令
-s, --shell

run shell as the target user;

a command may also be specified

由目标用户运行 Shell;

也可指定命令

-t, --type=type create SELinux security context with specified type 创建具有指定类型的 SELinux 安全上下文
-U, --other-user=user

in list mode,

display privileges for user

在列表模式下,

显示用户特权

-u, --user=user run command (or edit file) as specified user name or ID 由指定用户名或 ID 运行命令 (或编辑文件)
-V, --version display version information and exit 显示版本信息并退出
-v, --validate update user's timestamp without running a command 更新用户的时间戳 (不运行命令)
-- stop processing command line arguments 停止处理命令行自变量

基本用法

功能 命令 文字解释 示例 示例解释
用户 sudo su 变更用户登入身份为 root sudo su ls-ubuntu 变更用户登入身份为 ls-ubuntu
Shell sudo -i -u USER 以 USER 用户登录 Shell sudo -i -u postgres 以 postgres 用户登录 Shell
sudo --login --user USER sudo --login --user postgres
帮助 sudo -h 展示帮助信息
sudo --help
版本 sudo -V 展示版本信息
sudo --version

 

版权声明: 本文为独家原创稿件,版权归 乐数软件 ,未经许可不得转载。