Quick take: The su command switches to another user, prompting for that user's password. su - starts a full login shell as root, su - alice becomes alice, and su -c 'cmd' alice runs a single command as them.

Introduction

The su command (substitute user) lets you become another user within your current session, most often root. Unlike sudo, which runs one command with your own password, su starts a session as the target user and asks for their password — a different model worth understanding.

Syntax

The basic syntax of the su command is:

su [OPTIONS] [USER]

Common Options and Parameters

The most useful options and parameters for the su command:

OptionDescription
(no user)Switch to root.
-, -lStart a login shell with the target user's environment.
-c CMDRun a single command as the target user.
-s SHELLUse a specific shell.
USERSwitch to the named user instead of root.

Practical Examples

Real su commands you can run today:

# Switch to root (keeps your environment)
su
# Switch to root with a full login shell
su -
# Become another user
su - alice
# Run one command as another user
su -c 'whoami' alice
# Return to your own account
exit

Tips and Best Practices

  • Always prefer su - (with the dash) for root — it loads root's full environment and PATH, avoiding subtle issues.
  • On Ubuntu the root account is locked by default, so su fails; use sudo -i instead, or sudo su -.
  • Type exit (or Ctrl+D) to return to your original user when finished.

Final Thoughts

su switches you into another user's session, asking for their password and (with -) loading their environment. On modern systems sudo is usually preferred for elevated commands, but su remains useful for becoming a service account or root where it is enabled. Remember the dash for a proper login shell, and exit to come back.

FAQ: su Command in Linux

What is the difference between su and sudo?+

su switches to another user's session and asks for that user's password, while sudo runs a single command as another user (usually root) and asks for your own password. sudo is preferred for granular, logged privilege escalation.

What does su - do?+

The dash starts a full login shell as the target user, loading their environment, PATH, and home directory — as if they had logged in directly. Without it, su keeps your current environment.

Why does su fail on Ubuntu?+

Ubuntu locks the root account's password by default, so su has no password to accept. Use sudo -i or sudo su - to get a root shell instead.

How do I run one command as another user?+

Use su -c: su -c 'command' username runs a single command as that user and then returns you to your own shell.

How do I exit su?+

Type exit or press Ctrl+D to leave the substituted user's shell and return to your original account.

Need help with Linux servers or infrastructure?

Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.

Hire Me for Support