Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 2989  / 3 Years ago, sun, august 22, 2021, 12:06:09

It seems as if there is no difference whatsoever. When the whoami or id commands are run, they all yield root credentials. Is this an illusion? If the root account is disabled by default in Ubuntu, and therefore su gives and authentication error, then why allow sudo -I



Edit: Excuse me, the ONLY difference I have learned of is that sudo -I asks for the password of the user who invoked the command, and su asks for root, or some other target user's password.



Is there any OTHER difference?


More From » sudo

 Answers
4

EDITED. Note: This answer has been heavily edited since its last iteration based on Eliah Kagan's comments.



sudo -i runs a login shell with root privileges, simulating an initial login with root, acting similar to su -. The primary difference between sudo -i and su - is that sudo -i can be executed using a sudoer's password, while su - must be executed with the root account's password. Hence, if you are on a default *buntu install, where root login is disabled, sudo -i can be used while su and its variants cannot.



If you run the following commands:



$ sudo -i
[sudo] password for <username>: <enter user's password>
# cd ~
# pwd


you will get the output:



/root


Hence, you can see that sudo -i simulates an initial root login, including changing the home folder ($HOME) to root's, rather than your own. This also means sudo -i reads login files like .profile.



Meanwhile, sudo -s starts a new shell but without simulating initial login - login files are not read and $HOME is still set to your user's home folder.



If you run the following commands:



$ sudo -s
[sudo] password for <username>: <enter user's password>
# cd ~
# pwd


you will get the output:



/home/<username>


From this, you can see that sudo -s does not simulate an initial login, and does not change $HOME.


[#26490] Tuesday, August 24, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
istmasted

Total Points: 287
Total Questions: 130
Total Answers: 153

Location: Burkina Faso
Member since Thu, Dec 23, 2021
2 Years ago
;