Understanding su, su -, sudo -i, and sudo -s in Linux

Do you really know what each one is for?

Kesk -*-
CodeX

--

Photo byKlaus Nielsen

Understanding Linux systems can be a bit like choosing from a menu with lots of options. In the world of superuser commands, we have four main choices: su, su-, sudo -i and sudo -s. Each of these commands has its own special features, and it’s simple to get them mixed up. Let’s simplify things to help you choose the right one!

su

The su command stands for 'substitute user' and allows you to switch to another user account, typically the root user, by entering the target account's password. However, it does not set up the target user's environment, meaning you keep your own environment variables and working directory."

Example:

su
Password: [Enter root password]

su -

Including a hyphen (-) after su: su - is significant because it expands our options. It’s also known as “su with a hyphen” or “su with a minus sign.” This command not only switches to the target user but also fully replicates that user’s environment, including their home directory and environment variables. This is the recommended way to become the root user when you need to perform administrative tasks as it provides a clean environment.

--

--

Kesk -*-
CodeX
Writer for

Software engineer - software Enthusiast - Sci-Fi writer.