Permissions, users and access

Command su

Switch to another user

Linux · Bash examples · commands run on the selected server

When to use su

Use su to start a shell as another local account when policy permits. A login shell refreshes more of the account environment, which matters for home directories, startup files and command lookup.

Syntax

su [OPTIONS] [USER]

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-
Launch the login shell with the target user's environment.
-c COMMAND
Execute one command.
-s SHELL
Select shell if permission is available.

Usage examples

Switch to test account

su - deploy

A login shell starts for the target account with its login environment.

Verify identity from another user

su - deploy -c 'id'

The identity check runs as the target account and the command then exits.

Open Bash as another user

su -s /bin/bash deploy

A specific shell is requested, subject to account and system restrictions.

Notes and limitations

  • su typically asks for the target account's password; PAM policy can change behavior.
  • To exit a nested shell, run exit; on servers it is often more convenient to use the limited sudo.

Common questions and troubleshooting

Does su use my password or the target password?

That depends on authentication policy and privilege. On common local configurations it asks for the target account's password; do not assume sudo semantics.

Why does the environment differ after switching users?

Login and non-login modes initialise different variables and startup files. Verify identity, home directory and command path in the new shell.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man su.