LinuxCommandLibrary

runuser

Run commands as a different user

TLDR

Run command as different user

$ runuser [user] -c '[command]'
copy
Run as user and group
$ runuser [user] -g [group] -c '[command]'
copy
Start login shell
$ runuser [user] -l
copy
Use specific shell
$ runuser [user] -s /bin/bash
copy
Preserve environment
$ runuser [user] -p -c '[command]'
copy

SYNOPSIS

runuser [-l] [-c command] [-g group] [-s shell] [-p] user

DESCRIPTION

runuser runs commands as another user without requiring password authentication. Unlike su, it's designed for use by root in system scripts and services where interactive authentication isn't appropriate.
The tool is commonly used in init scripts and system services to drop privileges to a specific user before executing commands.

PARAMETERS

-c, --command _command_

Command to execute
-g, --group _group_
Specify group
-l, --login
Start login shell
-s, --shell _shell_
Use specific shell
-p, --preserve-environment
Keep environment variables
-w, --whitelist-environment
Preserve specific variables

CAVEATS

Requires root to run. No password prompt (unlike su). Environment handling depends on options. Login shell resets most environment.

HISTORY

runuser is part of util-linux, providing a non-interactive way for root to run commands as other users. It's preferred over su in scripts due to its predictable behavior.

SEE ALSO

su(1), sudo(8), runcon(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community