0

What does this command? sudo -i?

I'm not sure if I should have made a post with just this question, but since I'm a Linux newbie and I have a lot more questions and doubts, I decided to go ahead and ask. That shouldn't hurt I guess.

And many thanks in advance for the help :)

Aryetsok
  • 21
  • 3

2 Answers2

2

sudo -i starts another bash session as root and uses the directory /root as home directory. If you want to enter a root shell, you should almost ever use sudo -i

To use your current user's directory as home, use sudo -s. Never start GUI applications from a shell started with sudo -s. The process may transfer the ownership of some important files to the root user, so you can't use them any more!. So use sudo -i to enter root shells you want to execute GUI-applications from.

If you just want to execute a program as root, use sudo program for command line programs and gksudo program for GUI applications.

s3lph
  • 14,644
  • 12
  • 60
  • 83
1

The behavior of sudo -i is well documented in man sudo (somewhere at the line 137):

 -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.

See also:

Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407