8/10/2023 0 Comments Su vs sudo su![]() ![]() Non-login users are useful for daemon processes in your operating system. If you do use it for a user with no password, then you need to be either root or You can use it for non-login users, and for users who don't have passwords. This is an easy way to test how a command will run under a different user: su -s /bin/bash -c '/path/to/your/script' testuser Non-sudoer, it is impossible for you to switch to those users, or run commands as those If you are not a sudoer, then you can only use the su commands, which requires If you're a sudoer, it would be easier to just use the sudo commmands. Note that running su under sudo seems to always discard environment variables,Įven if you try to preserve it with a -p option. Switching users always involves creating a subshell, it does not replace the existing # there is a `-E` option that will preserve the environment variables even after logging in # run a command using the user without activating a shell (it runs the command directly, so the process tree is shell - sudo - id) Running sudo -i is a cleaner (in my opinion) way of running sudo. 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. su just switches the user, providing a normal shell with an environment nearly the same as with the old user. There's a subtle difference between the two. When using sudo, we require sudoers privileges and enter the current user’s passphrase. Critically, the significant way sudo su and su differ comes down to which password we need to enter. The difference in the process tree is a single process sudo. A login shell resets most environment variables, providing a clean base. After that, we check the output of pstree after the switch to the superuser. # login to a shell as the user, using the sudo password, discarding enviroonment variables, will activate a login and interactive shell 4 Answers Sorted by: 281 su - invokes a login shell after switching the user. bashrc script will be run before executing the su - root command. ![]() the most distinguishable difference between the 2 is that the SU command is. sudo su lauches su directly with super user privileges, while sudo bash lauches the shell first and then executes the command with bash -c. As mentioned above, root user can do su - without. The SU command stands for Substitute user whereas SUDO stands for Super User Do. Observed on Debian Wheezy with htop: sudo su - has a child of su -, and su - has a child of -su. Once you exit (eg., Ctrl-D) from sudo su -, the execution of sudo will end. # start shell as the user, using the sudo password, discarding environment variables, will activate a non-login and interactive shell Long answer: it is different from doing su - within a root shell. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |