Commands.page Logo

Difference Between Sudo -i and Sudo -s in Ubuntu

In Ubuntu Linux, managing administrative tasks often requires elevated privileges using the sudo command. Two common flags, -i and -s, allow users to start a root shell, but they function differently regarding environment variables and home directories. This article explains the specific distinctions between sudo -i and sudo -s to help you choose the right tool for your system administration tasks.

sudo -i: Simulated Initial Login

The sudo -i command runs a login shell as the root user. It simulates a full login process, meaning it initializes the environment as if root had logged in directly. This command changes the working directory to the root user’s home directory (/root) and loads root’s specific profile scripts, such as .profile and .bashrc. Most environment variables are reset to reflect the root user’s settings rather than inheriting them from the current user.

sudo -s: Non-Login Shell

The sudo -s command starts a non-login shell with root privileges. It preserves the current user’s environment variables and does not change the working directory unless explicitly told to do so. This means you remain in your current folder, and settings like PATH or HOME usually reflect your original user account while granting you administrative execution rights. It is generally faster than -i because it skips the login initialization scripts.

Key Differences Summary

When to Use Each Command

Use sudo -i when you need a clean root environment to perform system-wide configurations or when scripts depend on root’s specific path settings. Use sudo -s for quick administrative tasks where you want to maintain your current working context and environment variables without the overhead of a full login simulation.