Use for sudo -i

I am trying to figure out what sudo -i is for.

It looks like it lets you run as root without having to input your password.

But my aliases no longer work ?

My aliases are in .bash_aliases.

I think in this case the aliases need to be defined in /root/.bash_aliases as well, as the profile of the root user is being used.

sudo -i “logs in” as the root user. Similar to running sudo bash.

From man sudo:

     -i, --login
                 Run the shell specified by the target user's password data‐
                 base entry as a login shell.  This means that login-specific
                 resource files such as .profile or .login will be read by the
                 shell.  If a command is specified, it is passed to the shell
                 for execution via the shell's -c option.  If no command is
                 specified, an interactive shell is executed.  sudo attempts
                 to change to that user's home directory before running the
                 shell.  The command is run with an environment similar to the
                 one a user would receive at log in.  The Command environment
                 section in the sudoers(5) manual documents how the -i option
                 affects the environment in which a command is run when the
                 sudoers policy is in use.

So under this, you’ll be performing commands as the root user, so you’d be using root’s own .bash_aliases (as @maximuscore points out)

Take caution if you’re making changes in your “normal” home directory, as new files/folders will be owned by root.

1 Like

thanks gentlemen for the info.

I will stick to regular sudo and gksudo.