9/3/2023 0 Comments Sudo vs su root![]() ![]() The command is run with an environment similar to the one a user would receive at log in. sudo attempts to change to that user's home directory before running the shell. If no command is specified, an interactive shell is executed. If a command is specified, it is passed to the shell for execution via the This means that login-specific resource files Run the shell specified by the target user's password database entry as a login shell. Provide an environment similar to what the user would expect had the user logged in directly. sbin:/bin:/usr/sbin:/usr/bin for the superuser The value of $PATH is reset to /bin:/usr/bin for normal users, or These options are documented under man sudo. The -u user option means to run the command as the specified user rather than root. The -s option means to run the shell specified in the environment variable SHELL if this has been set, or else the user's login shell. Running sudo -i is a cleaner (in my opinion) way of running sudo su. Running su as root is essentially a no-op, though it probably starts a new shell. sudo runs the specified command ( su) as root. su root (which can be shortened to just su) runs the su command as the user who invoked it. The current environment is passed to the new shell. sudo -su user is short for sudo -s -u user. There's a subtle difference between the two. You can run the program under sudo -i as you were logged as root with su -,īut you can have different behaviour if you run it with sudo M圜ommand or with su -c M圜ommand. The -s option means to run the shell specified in the environment variable SHELL if this has been set, or else the users login shell. in /home/$USER/bin instead then the one in the path expected from root. sudo -su user is short for sudo -s -u user. In particular a user can have a different order of the directories in his $PATH and, as a consequence, a script can execute a command e.g. Each user can modify his environment in a different way (variables, $PATH. It reads the file related with the $HOME. So a script, or a program that is launched with a different option can see different $PATH, $HOME, its shell can read different. Where =/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binĮnv=Environment variables are reset for 1 and 5, taken from $USER in 2,3,4. sudo su (root) root USER :/usr/games:/usr/local/games on the system on which I am in this moment. However, in the case that the SHELL environment variable is set in the invoking user's environment (which it usually is, and it is typically /bin/bash), and that the target user has a login shell which differs from this (such as /usr/sbin/nologin), there is then a difference between which shell gets executed by these two commands, and this is what you are seeing.It strongly depends on how you call your program with sudo or su.Į.g. So the two commands look similar (largely coincidentally) and have a somewhat similar effect when the target user has the same login shell as that of the invoking user. ![]() The su user command could be run without the use of sudo, but by running it as root it will not require the password of the target user. The su command will then invoke the login shell of the specified username. Sudo su user will use sudo to run the command su user as the root user. ![]() ‘su’ Vs ‘sudo’ ‘su‘ forces you to share your root password to other users whereas ‘sudo‘ makes it possible to execute system commands without root password. Sudo -su user is short for sudo -s -u user. NOTE This article is more applicable to Ubuntu based distributions, but also applicable to most of the popular Linux distributions. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |