Files
tldr/pages.zh/linux/runuser.md

24 lines
634 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# runuser
> 以不同用户和组的身份运行命令无需输入密码需要root权限
> 更多信息:<https://manned.org/runuser>。
- 以不同用户身份运行命令:
`runuser {{user}} -c '{{command}}'`
- 以不同用户和组身份运行命令:
`runuser {{user}} -g {{group}} -c '{{command}}'`
- 以特定用户身份启动登录shell
`runuser {{user}} -l`
- 指定一个shell来运行而不是默认的shell也适用于登录
`runuser {{user}} -s {{/bin/sh}}`
- 保留root的整个环境仅在未指定`--login`时):
`runuser {{user}} --preserve-environment -c '{{command}}'`