8/23/2023 0 Comments Sudo vs su root![]() ![]() If you want to completely switch to the root account, then execute the sudo -i command without any arguments. It is similar to the sudo su command but way better because you do not have to directly interact with the root user.įor example, if you want to execute the whoami command without switching to the user, then specify the command as an argument to the sudo -i command and then it will ask for the current account password, as shown below. To prevent it from happening and get a cleaner version we will use the sudo -i command, which you are about to learn. However, sudo su creates multiple setuid which makes it more challenging to know which variable will be kept and which one will be changed.Īlso Read: How to Disable ‘su’ Access for Sudo Users in Linux When you access or switch to another user account, you are able to set environment variables. Same with the superuser account, which will require my current password when accessed using the sudo su command. It is recommended to give access to sudo and su to only trusted users and disable them for untrusted users.Īlso Read: Revoke Users SUDO privileges in LinuxĪs you see below, I will try to access the jake account without knowing its password but using my current password. Note: Giving access to sudo will let users switch to any account using the sudo su command, which might be unnecessary for them and system security. However, using sudo su to switch to another user account or superuser requires the current user password. The sudo su is similar to the standard su command, only the difference is that executing su will ask for that user account password. However, it also prevents a user from accessing the account if they do not know the target account password.įor example, in order to access the root account, I need to know the root account password otherwise, I’ll not be able to gain access.Īlso Read: Create New User with Sudo Privileges using Command-Lineīut don’t worry, there are a few more ways to access another user’s account or gain access to superusers without knowing their password, which we are about to learn. :/home/trendoceans# whoamiĪs you see, the su command is effective for switching to another account or superuser if you know their account password. To switch to a superuser or root account, execute su without any arguments, and then it will ask for the root account password, as shown below. If you want to switch to any specific user, like trendoceans, then specify the su with username as an argument and then it will ask for a user password that you need to enter in order to get account access, as shown below. If you run the following commands: $ sudo -sįrom this, you can see that sudo -s does not simulate an initial login, and does not change $HOME.The su command is the most basic command to switch a current user to another account or superuser without changing the current working directory and user environment. 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. This also means sudo -i reads login files like. 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. If you run the following commands: $ sudo -i 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. 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. Sudo -i runs a login shell with root privileges, simulating an initial login with root, acting similar to su. Note: This answer has been heavily edited since its last iteration based on Eliah Kagan's comments.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |