Why is one preferred over the other in this example?
sudo su echo "options iwlwifi 11n_disable=1" >> /etc/modprobe.d/iwlwifi.conf exit
Please provide links to Ubuntu documentation.
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
sudo su command stands for "switch user", and allows you to become another user. It allows a permitted user to execute a command as the superuser or another user, as specified in the sudoers file.
The ‑i (simulate initial login) option runs the shell specified by the password database entry of the target user as a login shell. This means that login-specific resource files such as .profile or .login will be read by the shell. If a command is specified, it is passed to the shell for execution via the shell's ‑c option. If no command is specified, an interactive shell is executed.
sudo su only changes the current user to root. Environment settings (like PATH) remain the same.
sudo -i creates a fresh environment as if root had just logged in.
The difference is more noticeable if you use other users. After
sudo su bob you will be bob, but in the same place. After
sudo -i -u bob you will be bob, in bob's home directory, with bob's default shell and with bob's
.profile and any other login scripts having been run.
Found a version of
man su (from login-1:188.8.131.52+svn3283-3ubuntu5.1) that has the following to say:
$PATH reset according to the /etc/login.defs options ENV_PATH or ENV_SUPATH (see below);
$IFS reset to “<space><tab><newline>”, if it was set.
Note that the default behavior for the environment is the following:
The $HOME, $SHELL, $USER, $LOGNAME, $PATH, and $IFS environment variables are reset.
If --login is not used, the environment is copied, except for the variables above.
If --login is used, the $TERM, $COLORTERM, $DISPLAY, and $XAUTHORITY environment variables are copied if they were set.
Other environments might be set by PAM modules.
So whether and to what extent
sudo su changes the environment depends on your distribution and setup. Thus
sudo -i is theoretically more portable.
The main problem is one of (not so) sane environment settings.
sudo su the new shell gets its environment from the user who issues the command - which may be problematic.
sudo -i you get a clean root shell.
Remains to observe that it is rarely necessary at all to create a root shell.