Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between "sudo -i" and "sudo su -" [closed]

Tags:

linux

bash

unix

Both commands will log me in as root. I know there is a difference in what environment settings are set.

Which one do you use? Which one is better practice?

like image 469
slimlambda Avatar asked Mar 14 '16 22:03

slimlambda


People also ask

Is sudo the same as su root?

sudo vs su Command The sudo command lets us use our account and password to execute system commands with root privileges, whereas the su command allows us to switch to a different user and execute one or more commands in the shell without logging out from our current session.

What does sudo su means?

sudo lets you issue commands as another user without changing your identity. You need to have an entry in /etc/sudoers to execute these restricted permissions. sudo -i brings you to an interactive session as root. su means to switch to a particular user. Just typing su switches to the root user.

Is su password same as sudo?

It is configurable* but, by default, "sudo" asks you for your password. It is just trying to make sure that it is you, not someone using your keyboard while you were getting coffee. By contrast, "su root" asks you for the root password.


2 Answers

su has only one purpose: to start a shell running as the given user (root by default).

sudo is a highly configurable program that lets you run any command as any user, with the configuration allowing the local administrator to place limits on what commands you can run using sudo, as well as which commands require your password.

su is (I believe) the older program which allows you to do anything the given user can do, which is often more than you need. sudo is safer in that it can be tailored to allow you just enough authority to run the commands you need, nothing more.

like image 154
chepner Avatar answered Nov 15 '22 21:11

chepner


http://linux.die.net/man/8/sudo

The -i (simulate initial login) option runs the shell specified by the password database entry of the target user 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 security policy shall initialize the environment to a minimal set of variables, similar to what is present when a user logs 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.

like image 35
zsolt.k Avatar answered Nov 15 '22 22:11

zsolt.k