![]() ![]() ![]() For example, if you run touch -R you'll receive an error saying that -R is not an option to touch, but if you run touch -R it will create a file named -R. Passing a double-hyphen to a command is typically used to mark the end of command-line flags and the beginning of non-flag arguments. This includes setting your directory to your home directory and setting a bunch of other environment variables. Provide an environment similar to what the user would expect had the user logged in directly. The man page for su describes the behavior as: Passing a single hyphen is identical to passing -l or -login. (In our case, that would be “~/.config/fish/config.fish”.) For all intents and purposes, it’s best to leave things that way rather than copying over the user configuration to “/root”.Ĭhanging to your user account’s shell when swapping over to root should only be done if you need to run a script that absolutely needs that particular shell.When you provide a double-hyphen the experience you will have is identical to if you had just executed sudo su without any hyphen. If you don’t have such a thing, it will just load the default configuration instead of your personal one. 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. This command summons a shell with your $SHELL variable. In simpler language: sudo -i will give you a “clean” root login in your “/root” folder, which is the “home” folder for the root user. Because of this, most people view it as the preferred method to gain root without logging in directly. This makes it much more challenging to figure out which environmental variables will be kept and which will be changed (when swapping to the root environment). To clarify: with sudo su, you’re using more than one root setuid command in the background. Where it differs from sudo su is that sudo -i is a much cleaner way of gaining root and a root environment without directly interacting with the root user. ![]() sudo -i is also very similar to using sudo su: it’ll read all of the environmental files (“.profile”, etc.) and set the environment inside the shell. Much like sudo su, the -i flag allows a user to get a root environment without having to know the root account password. Using sudo -i is virtually the same as the sudo su command with one exception: it does not directly interact with the root user. While you could do this in the meantime, you should still reset the root password at some point. 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). 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. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |