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?
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?
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.
su
stands for 'substitute user' and not 'switch user' (or even 'super user'). –
Seymore © 2022 - 2024 — McMap. All rights reserved.
sudo -i -u username
and check your Environment Variables then runsudo su - username
and check your Environment Variables You should see a difference – Kunkelsudo su
, then your PAM configuration forsu
matters in addition to yoursudoers
config; if only usingsudo
, then you're depending only onsudo
(and all the configuration included therein by reference -- its PAM modules, its configuration, etc), whereas usingsu
in addition means you're depending on two tools with independent behavior and configuration (and on the former to be configured to allow the latter). – Deodarsudo -i -u someuser
doesn't set variables from/etc/environment
butsudo su - someuser
does. (sudo -i
on this Ubuntu 14.04 system used to work.) – Achromat