u---user Verified current stable Not installed? System Operations

U User / Run Command As Another User

Run Command As Another User

Execute a command as a specific user while optionally changing group membership.

$
Terminal
sudo -u <user> -g <group> <id -a>

When To Use

When accessing resources that require permissions of another user or group while auditing user-specific actions.

Pro Tip

Use the `--preserve-environment` option to maintain current environment variables when switching users.

Command Builder

Tune the command before you copy it

Back to syntax
$
Generated Command
sudo -u <user> -g <group> <id -a>

Anatomy of Output

Understanding the result

uid=1001(user) gid=1001(group) groups=1001 Output of `id` Command

Displays effective user ID, group ID, and groups associated with the user.

groups=users, admin Group Membership

Indicates which groups the user is part of.

su - user User Switch Command

Indicates the switch to specified user.

Troubleshooting

Common pitfalls

Error: user 'nonexistent' does not exist

Solution: Verify the target username before executing the command.

Error: permission denied for command execution

Solution: Ensure you have sudo privileges to switch users.

Error: invalid group specified

Solution: Check the specified group name for correctness.

Command Breakdown

What each part is doing

sudo
Base Command
The executable that performs this operation. Here it runs U User before the shell applies any redirect operators.
-u
u| user
The user value supplied to this command.
<user>
user
The user value supplied to this command.
-g
g| group
The value supplied for g| group.
<group>
group
The value supplied for group.
<id -a>
id a
The value supplied for id a.
-u
Command Option
Tool-specific option used by this command invocation.
-g
Command Option
Tool-specific option used by this command invocation.
-a>
Command Option
Tool-specific option used by this command invocation.

Alternative Approaches

Comparable commands in other tools

Alternative system operations tools for the same job.