shotsvorti.blogg.se

Su vs sudo
Su vs sudo












su vs sudo

#Su vs sudo password

If you don’t have such a thing, it will just load the default configuration instead of your personal one. su means to switch to a particular user Just typing su switches to the root user sudo will ask for your password, while su will ask for the password for the user whom you are switching to Want to learn more about security Check out the IT security and compliance checklist. The shell will follow whichever configuration you have in root’s home folder. Loading the user shell by using sudo -s yields a drastically different result. But if you run anything else, you’ll immediately notice how different things can be!įor example, let’s say you’re running the fish shell for your user account and keep the root shell in bash. In most instances, elevating to root through either shell will not result in any noticeable change. If you use an unmodified bash shell for your user account, the difference is mostly philosophical. Using sudo -i is virtually the same as the sudo su command with one exception: it does not directly interact with the root user. In case of su - command, the first thing that runs is changing the user and only then the shell. While you could do this in the meantime, you should still reset the root password at some point. In the case of su and su - we also have significant differences. The difference between the su command without flags and su with a hyphen or -l is the command without flags keeps your environment variables and only changes. This is useful in situations where you may have forgotten the root password if it’s different from the password for your user account. Root is given with sudo su by requesting the current user’s password, which makes it possible to gain root without the root password. Though there isn’t a large divergence between sudo su and su, the former is still a very useful command for one important reason: when a user is running su to gain root access on a system, they must know the root password. If any command is run with sudo in front of it, it is given root privileges. When sudo su is run, “.profile,” “.bashrc” and “/etc/profile” will be started, much like running su (or su root). 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’s essentially the same as just running su in the shell, save for one crucial difference: instead of telling the system to “switch users” directly, you’re telling it to run the su command with superuser privileges. sudo su - username will do the same, but first ask the system to be elevated to super user mode, after which su will not ask for 'username''s password because a super user is allowed to change into any other user without knowing their password. 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. 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. Sudo -su user is short for sudo -s -u user.














Su vs sudo