su (switch user) Study Notes

su (switch user)

su switch user or substitute user. It lets you change your current user session to another user account.

su username

-c or --command

Run a single command as another user:

su -c "command" username

If you run it without specifying a user, the system defaults to the root user:

su -c "command"

This runs the command as root, then exits.


- or -l or --login

Start the shell as a login shell with an environment similar to a real login.

su - username

If you run it without specifying a user, the system defaults to the root user:

su -

-s or --shell

Run the specified shell instead of the default.

su -s /bin/bash -c "command" username