๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

๐Ÿ’ก User Management September 4, 2026 1

Linux Command: su

Switch user or become superuser

Terminal โ€” User Management
Command
$ su -
Output
Password:

su (substitute user) switches the current user identity to another user, requiring that user's password. Without a username, it switches to root. su creates a new shell running as the specified user. The - flag (su -) is important โ€” it simulates a full login, loading the target user's environment, PATH, and shell initialization files. While su is still available, sudo is generally preferred for administrative tasks because it provides better auditing, does not require sharing the root password, and allows more granular access control.

Syntax

su [OPTION]... [USER]

Key Options

  • - โ€” Full login shell (load user environment)
  • -c โ€” Execute a single command
  • -s โ€” Use specific shell
  • -l โ€” Same as - (login shell)
  • -p โ€” Preserve current environment

Examples

Switch to root

su -

Output: Password:

Switch to user

su - www-data

Run single command

su -c 'cat /etc/shadow' root

Pro Tips

  • su without dash keeps your current environment, which can cause confusion. su - loads the target user environment properly.
  • sudo uses YOUR password and logs commands. su requires the TARGET user password. sudo is preferred for admin tasks.
  • Service accounts often have /sbin/nologin as shell. Use su -s /bin/bash username to get a shell.

Learn more: Full su reference โ†’

Share this tip