Su Command in Linux (Switch User)

The su (short for substitute or switch user) utility allows you to run commands with another user’s privileges, by default the root user. If you’re looking for running single commands with elevated privileges, see our sudo command guide
.
Using su is the simplest way to switch to the administrative account in the current login session. This is especially handy when the root user is not allowed to log in to the system through SSH
or using the GUI display manager.
In this guide, we will show you how to use the su command with practical examples.
Syntax
The general syntax for the su command is as follows:
su [OPTIONS] [USER [ARGUMENT...]]When invoked without any option, the default behavior of su is to run an interactive shell as root:
suYou will be prompted to enter the root password, and if authenticated, the user running the command temporarily becomes root.
sudo, which asks for your own password, su requires the password of the target user you are switching to.To confirm that the user is changed, use the whoami command:
whoamirootTo switch to another user account, pass the user name as an argument to su. For example, to switch to the user tyrion you would type:
su tyrionTo start a login shell as another user:
su - tyrionLogin Shell vs Non-Login Shell
When you run su without the - option, the SHELL and HOME environment variables
are set from the target user’s /etc/passwd
entry, but the current directory and the rest of the environment are not changed. This means the PATH variable still contains the original user’s directories.
The most commonly used option when invoking su is - (-l, --login). This starts a login shell with an environment identical to a real login, including changing the current directory
to the target user’s home:
su -In most cases, you want to use su - rather than plain su to get a clean environment.
Options
The su command accepts the following options:
Run a Specific Shell (-s)
To run a shell other than the one defined in the passwd file, use the -s, --shell option. For example, to switch to root and run the zsh shell:
su -s /usr/bin/zshPreserve the Environment (-p)
To preserve the entire environment (HOME, SHELL, USER, and LOGNAME) of the calling user, use the -p, --preserve-environment option:
su -pWhen the - option is used, -p is ignored.
Run a Single Command (-c)
To run a command as the target user without starting an interactive shell, use the -c, --command option. For example, to invoke the ps
command as root:
su -c 'ps aux'To run a command as a specific user:
su -c 'whoami' tyrionThe command string should be quoted if it contains spaces or special characters.
Sudo vs Su
On some Linux distributions like Ubuntu, the root user account
is disabled by default for security reasons. This means that no password is set for root, and you cannot use su to switch to root.
One option to change to root would be to prepend the su command with sudo and enter the currently logged-in user password:
sudo su -The sudo command allows you to run programs as another user, by default the root user.
If the user is granted sudo access, the su command is invoked as root. Running sudo su - and then typing the user password has the same effect as running su - and typing the root password.
When used with the -i option, sudo runs an interactive login shell with the root user’s environment:
sudo -isudo -i is functionally the same as running su -.
The key differences between sudo and su:
- Password:
surequires the target user’s password.sudorequires your own password. - Access control:
sudoallows fine-grained control over which commands a user can run (configured in/etc/sudoers).sugives full access to the target user’s account. - Auditing:
sudologs every command that is run.suonly logs that a user switched accounts. - Root password:
sudoeliminates the need to share the root password among multiple administrators.
Quick Reference
| Task | Command |
|---|---|
| Switch to root | su |
| Switch to root (login shell) | su - |
| Switch to another user | su username |
| Run a command as root | su -c 'command' |
| Use a specific shell | su -s /bin/zsh |
| Preserve environment | su -p |
| Switch to root via sudo | sudo su - |
| Sudo login shell | sudo -i |
FAQ
What is the difference between su and su -?su switches to the target user but keeps most of the current environment, including PATH and the working directory. su - starts a full login shell with the target user’s complete environment.
What is the difference between su and sudo?su switches your entire session to another user and requires that user’s password. sudo runs a single command (or opens a shell) with elevated privileges using your own password.
Why does su ask for a password even though I am root?
If you are already root, su does not ask for a password. If it does, you may be in a non-root shell that looks like root (e.g., changed prompt). Use whoami to verify.
How do I restrict which users can use su?
On most distributions, you can restrict su access to members of the wheel group by configuring PAM. Edit /etc/pam.d/su and uncomment the line containing pam_wheel.so.
Conclusion
The su command allows you to switch to another user account and run commands with that user’s privileges. In most cases, sudo is the preferred method for running commands as root because it provides better access control and auditing.
If you have any questions, feel free to leave a comment below.
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page