Linux Terminal Command: su

The su command is an essential tool in User & Permission Management. In this tutorial, we will explore what su does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.


Concept & Explanation

The su (substitute user) command switches the current login session to another user. If no username is specified, it defaults to switching to root.


Common Options & Syntax

su [options] [arguments]

Here are the most common flags used with su:


1. Interactive Example (Simple)

Here is how most people run the command:

# Example
su - admin

What it does: Switches session to user ‘admin’, initializing their login shell environment.


2. Power-User Example (Advanced)

For scripting and advanced diagnostics, use this configuration:

# Advanced
su -c 'service nginx restart' root

What it does: Executes the restart command as root and immediately returns back to your regular shell session.


⚙️ Warning & Common Pitfalls

[!WARNING] Always use su - (with a hyphen) instead of bare su. The hyphen initializes the target user’s path, variables, and home directory, avoiding path resolution bugs.


Here are some related posts on cli_tty1 you might want to check out: