KIM COMPUTER


su (Substitute User / Switch User)

The su command is used to become another user during a login session. Without leaving the current terminal, it allows you to switch to any user, most commonly the root user for administrative tasks.


1. Basic Usage

su [options] [username]

2. Key Options and Differences

Option Name Description
-, -l login Login Shell. Starts the shell as a login shell, loading the target user's environmental variables (PATH, HOME, etc.). (Highly recommended)
-c command Executes a single command as the target user without opening a new shell session.
-s shell Uses a specific shell (e.g., /bin/bash) for the session.

3. Practical Examples

① Switching to root with full environment

The hyphen (-) ensures that you inherit the root user's PATH and settings.

su -

② Switching to a specific regular user

su - kimcomputer

③ Running a single command as root

su -c "tail /var/log/auth.log"

4. [Note] su vs. sudo

  1. su: Requires the password of the target account (e.g., the root password). It switches the identity completely.
  2. sudo: Requires the password of the current user. It grants temporary administrative privileges for a specific task. This is generally considered more secure.