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 :)

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,314
  • 11
  • 59
  • 82
  • I understood you perfectly. I usually just do what you said 'sudo program' and it does the job, but I also like to learn :) Thanks for your time and help ;) – Aryetsok Apr 30 '14 at 19:10
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
  • 169,590
  • I also don't know what is that command 'man'. So noob :( I ran it on console and I believe I have an idea how to use it. Still pretty foggy on what I can do with it. Thanks for that information, it helped anyway :) – Aryetsok Apr 30 '14 at 19:12
  • @Aryetsok See man man :) – Radu Rădeanu May 01 '14 at 04:56