su Cheatsheet
Basic Syntax
Core su command forms.
| Command | Description |
|---|---|
su |
Switch to root using the current shell environment |
su - |
Switch to root with a full login shell |
su username |
Switch to another user |
su - username |
Switch to another user with a login shell |
su --help |
Show available options |
Login Shell vs Current Shell
Choose whether to keep the current environment or start a clean login session.
| Command | Description |
|---|---|
su |
Keep most of the current environment |
su - |
Load the target user’s login environment |
su - username |
Change to the target user’s home directory and shell |
whoami |
Confirm the current effective user |
pwd |
Check whether the working directory changed |
Run a Command as Another User
Use -c to run a single command without starting a full interactive shell.
| Command | Description |
|---|---|
su -c 'whoami' |
Run a single command as root |
su -c 'id' username |
Run a command as another user |
su -c 'ps aux' |
Run a quoted command with spaces |
su -c 'cd /tmp && pwd' username |
Run a compound shell command |
su -c 'echo $HOME' username |
Check the target user’s home in a non-login shell |
Shell and Environment
Adjust the shell or preserve the caller’s environment when needed.
| Command | Description |
|---|---|
su -s /bin/bash username |
Use Bash as the target shell |
su -s /usr/bin/zsh username |
Use Zsh as the target shell |
su -p |
Preserve the current environment |
echo $HOME |
Check the current home directory |
echo $SHELL |
Check the current shell |
Root Access Patterns
Compare common root-shell workflows.
| Command | Description |
|---|---|
su |
Prompt for the root password |
su - |
Prompt for the root password and start a login shell |
sudo su - |
Use sudo to start a root login shell |
sudo -i |
Start a root login shell without calling su directly |
exit |
Leave the current su shell |
Troubleshooting
Quick checks for common su issues.
| Issue | Check |
|---|---|
Authentication failure |
Verify the target user’s password, not your own |
su: user username does not exist |
Confirm the account exists with id username |
This account is currently not available |
Check the target shell in /etc/passwd; service accounts often use /usr/sbin/nologin |
su keeps the old PATH |
Use su - to start a clean login shell |
| Root access fails on Ubuntu | The root account may be locked; use sudo -i instead |
Related Guides
Use these guides when working with users, passwords, and privilege escalation.
| Guide | Description |
|---|---|
| su Command in Linux | Full su guide with examples and sudo comparison |
| sudo Command in Linux | Run commands with elevated privileges |
| How to Change User Password in Linux | Set or reset passwords |
| useradd cheatsheet | Create and manage user accounts |
| How to Add User to Group in Linux | Manage group membership |
