The su command in Linux moves your shell from one account into another. The name stands for substitute user, though plenty of people read it as switch user. Admins reach for it to get root access, test how another account sees file permissions, or run a program under a different identity. Type su on its own and it heads straight for root.

When to Use the Linux Switch User Command

A handful of jobs bring it out again and again:

  • Dropping into root for administrative work
  • Logging in as another account to check file and command permissions, which comes up while configuring a Samba share
  • Running a program with someone else’s privileges, including a quick way to check which packages are installed
  • Tracking down access or permission trouble on a box

Before you switch, it pays to know which accounts actually exist. The Linux list users command shows them in a second, so you are not guessing at names.

Switch to Root With a Login Shell

This is the form most people want. You get root rights plus root’s own environment and PATH.

su -

The dash opens a login shell, loads root’s environment values, and drops you into /root.

Switch to a Specific User Account

Add a name after the dash and the session behaves as if that account just signed in.

su - username

Here username is the target account. The dash loads its login setup, which keeps PATH and permission clashes out of your way.

su Command Syntax in Linux

su [OPTION] [USER]

su shifts your shell into another account. OPTION flags change how the switch behaves, like opening a login shell or running a single command. USER is the target; leave it blank and su assumes root.

Options for the su Command in Linux

The flags below cover nearly everything you will do with su.

-, -l, –login

Opens a full login shell for the chosen account. It loads that account’s variables, sets the right PATH, and moves you into its home folder. The safest pick of the bunch.

su -l testuser

-c for a Single Command

Runs one command as another account, then exits. No interactive shell opens, which suits a one-off task such as starting the Docker daemon under a service account.

su -c "whoami" captain-levi

-p to Keep Your Environment

Holds the current environment values through the switch. The folder and PATH stay put. Daily use is discouraged because of security and PATH problems.

su -p user

-s to Choose a Shell

Picks a shell for the switch instead of the account’s default one.

su -s /bin/bash captain-levi

-m for Legacy Environment Handling

Keeps the active environment, the same way -p does. It hangs around mainly for older scripts. Skip it for routine work.

su -m user

-g to Set a Primary Group

Assigns a custom primary group after the switch rather than the account’s standard group. Useful when you are checking group-based file rights.

su -g developers captain-levi

–help

Prints the help text and quits. Nothing on the machine changes.

su --help

su – vs su: Login Shell or Non-Login Shell

One character changes a lot. The dash decides whether su loads the target account’s environment or keeps yours.

Behavioursu – [user]su [user]
EnvironmentLoads target account valuesKeeps current values
PATHSet from target profileStays as current PATH
Working folderMoves to target homeStays where you are
Login filesReadSkipped
ResultSafer choiceCan cause ownership trouble

su – [user] for a Login Shell

This mimics a full login from a terminal or an SSH session. It reads login files such as .bash_profile, sets the right PATH from the target profile, and moves you into the home folder. You can tidy those files later with vi editor commands if a PATH entry needs fixing. Programs then run with the binaries and rights you expect.

su -
root@hostname:/root#

su [user] Without a Login Shell

Here only the identity changes. The old environment stays active, the PATH carries over, and you remain in the current folder while login files go unread. The trouble surfaces as wrong command output and odd file ownership, and it gets worse during root switches.

If all you need is one admin task, adding your account to the sudo group and calling sudo is the cleaner route than a full account swap.

FAQs

What does the su command do in Linux?

su switches your current shell to another user account. Short for substitute user, it runs commands under that identity. With no name given, it targets root and asks for the target account’s password.

What is the difference between su and su -?

su keeps your current environment, PATH, and folder. su – opens a login shell, loading the target account’s environment and moving you to its home directory. The dashed form avoids most PATH and ownership issues.

How do I switch to root using su?

Run su – and enter the root password. The login shell loads root’s environment and PATH and places you in /root. Plain su also reaches root but keeps your existing environment.

Does su ask for my password or the target user’s?

su asks for the password of the account you switch to, not your own. sudo works the other way, asking for your password and checking the sudoers rules instead.

How do I run a single command as another user?

Use su -c “command” username. It runs the command under that account and exits without opening a shell. For example, su -c “whoami” captain-levi returns the target user’s name.

Image

Willie has over 15 years of experience in Linux system administration and DevOps. After managing infrastructure for startups and enterprises alike, he founded Command Linux to share the practical knowledge he wished he had when starting out. He oversees content strategy and contributes guides on server management, automation, and security.