runuser 切换执行命令的用户

发布时间: 更新时间: 总字数:221 阅读时间:1m 作者: IP上海 分享 网址

runuserLinux中用指定的 usergroup ID 执行命令


  • man runuser
  • runuser --help
runuser --help ...
$ runuser --help

 runuser [options] -u <user> [[--] <command>]
 runuser [options] [-] [<user> [<argument>...]]

Run <command> with the effective user ID and group ID of <user>.  If -u is
not given, fall back to su(1)-compatible semantics and execute standard shell.
The options -c, -f, -l, and -s are mutually exclusive with -u.

 -u, --user <user>               username
 -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 runuser(1).


runuser -l <username> -c '<command>'
runuser -l <username> -c '</path/to/command> arg1 arg2'

# 示例
runuser -l root -c '/usr/bin/whoami'
Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数