GO KALI FREE
User Management

su Linux Command

Switches to another user account or the root user.

What does su do?

Switches to another user account or the root user.

Syntax

su [options] [username]

Practical example

su - root

Questions about su

What is the difference between su and sudo?

`su` switches to another user entirely and requires that user's password. `sudo` runs a single command as root using your own password.

How do I switch to root with su?

Use `su -` or `su - root` to switch to the root user. You will be prompted for the root password. The `-` sets up root's environment.

What does the dash (-) mean in su -?

The dash `-` starts a login shell, loading the target user's environment variables and profile. Without it, you keep your current environment.

How do I exit from su?

Use `exit` or press Ctrl+D to leave the su session and return to your original user account.

How do I switch to another user?

Use `su - username` and enter that user's password. This gives you a shell with that user's permissions and environment.

How do I run a single command as another user?

Use `su -c 'command' username` to run a single command as another user without switching to an interactive shell.

Why is su better than logging in as root?

Using `su` or `sudo` is safer than direct root login because it provides an audit trail and reduces the risk of accidental system damage.

Related User Management

id

Prints user and group IDs (UID, GID) for the specified or current user.

sudo

Executes a command with superuser (root) privileges.

w

Displays who is logged in and what they are currently doing.

passwd

Changes the password for a user account.

who

Shows all users currently logged into the system with login details.

useradd

Creates a new user account on the system.