Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between `sudo -i -u user` and `sudo su - user`? [closed]

Tags:

bash

sudo

su

Both commands:

sudo -i -u username
sudo su - username

Will log me in as username if I enter my password. Is there actually any difference between these commands?

like image 852
Jan Dudulski Avatar asked Jul 29 '15 09:07

Jan Dudulski


People also ask

Whats the difference between sudo and Sudo su?

sudo vs su Both su and sudo elevate privileges assigned to the current user. The main difference between the two is that su requires the password of the target account, while sudo requires the password of the current user.

What is the difference between root and sudo user?

The sudo (superuser do) command is a command-line utility that allows a user to execute commands as the root or a different user. It provides an efficient way to grant certain users the appropriate permissions to use specific system commands or run scripts as the root user.

What is a sudo non root user?

sudo (superuser do) allows you to configure non-root users to run root level commands without being root. Access can be given by the root level administrator through configuration of the /etc/sudoers file.

What does sudo user do?

Sudo (superuser do) is a utility for UNIX- and Linux-based systems that provides an efficient way to give specific users permission to use specific system commands at the root (most powerful) level of the system. Sudo also logs all commands and arguments.


1 Answers

The su command stands for "substitute user", and allows you to become different user(super user). sudo su changes the current user to root but environment settings (PATH) would remain same. It allows user who have permissions to execute a command as the superuser or another user, as specified in the sudoers file.

With sudo -i you get a clean root shell. 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.

like image 175
sTg Avatar answered Sep 16 '22 20:09

sTg