$linuxjunkies
>

sudo-i(8)

Run a login shell as root or another user with a complete environment.

UbuntuDebianFedoraArch

Synopsis

sudo -i [-u user] [command]

Description

sudo -i invokes a login shell as root (or the specified user) with environment variables initialized as if you had logged in directly. This differs from sudo alone, which preserves your current user's environment.

The login shell reads startup files like .bash_profile or .profile, setting HOME, USER, MAIL, and PATH to match the target user. Useful for administrative tasks that depend on root's proper environment.

Common options

FlagWhat it does
-u userRun the shell as the specified user instead of root
-sRun the specified shell (can be combined with -i)
-HSet HOME environment variable to the target user's home directory
-EPreserve user's environment variables (use with caution)
-lUpdate timestamp file without running a command
-vValidate sudo credentials and extend timeout

Examples

Open an interactive root login shell with root's environment and home directory

sudo -i

Run whoami in a root login shell (prints 'root'), then exit

sudo -i whoami

Switch to an interactive login shell as the postgres user

sudo -i -u postgres

Run a command as www-data with proper HOME environment set

sudo -i -u www-data bash -c 'echo $HOME'

Access root shell for multiple administrative commands in sequence

sudo -i

Print root's home directory (usually /root)

sudo -i pwd

Related commands