What is the difference between commands sudo -i and sudo su -?
Are they the same?
Best Answer
They may provide functionally close to the same thing, but it seems 'sudo -i' is lighter weight and keeps some handy back references in your environment.
You can see the extra processes by looking at 'ps auxf' (f gives you a forest view)
Note that they are starting from the same bash process pid, 4482, but that su - seems to spawn another step.)
Your first 'sudo' is already elevating your access level to root. Running su without specifying a username inside sudo changes the current user to root twice.
Another way to investigate this is by running both commands with strace -f.
strace -f -o sudoi sudo -i
vs
strace -f -o sudosu sudo su -
If you diff those two straces, you'll see more exeve's being run for sudo su -.
One more thing.
sudo -i maintains the extra environment variables set by SUDO.
In your login shell's profile files you can set up some things that you will use during your session, and which only need to be done once. Some ideas:
create a temporary file containing the IP address you connected from, later on you can include it in some scripts setting firewall rules.
run ssh-agent, ask for your SSH keys, and store the SSH agent environment variables in a file.
if that is a limited machine, and your co-workers want to be aware of each others logins, write(1) messages informing them of your login.
In a non-login shell's files (.bashrc) you should configure your shell:
Fancy prompt
set aliases
set history options
define custom shell functions
export environment variables, (maybe PAGER, EDITOR if system-wide settings suck)
load ssh-agent variables saved in .bash_profile
Usually, you would include .bashrc from .bash_profile with the following. Then login shell gets all your customizations, and .bash_profile file does not have to duplicate things that are already in .bashrc.
aptitude is a wrapper for dpkg just like apt-get/apt-cache, but it is a one-stop-shop tool for searching/installing/removing/querying.
A few examples that apt might not supply:
$ aptitude why libc6
i w64codecs Depends libc6 (>= 2.3.2)
$ aptitude why-not libc6
Unable to find a reason to remove libc6.
$ aptitude show libc6
Package: libc6
State: installed
Automatically installed: no
Version: 2.9-4ubuntu6
Priority: required
Section: libs
Maintainer: Ubuntu Core developers <ubuntu-devel-discuss@lists.ubuntu.com>
Uncompressed Size: 12.1M
Depends: libgcc1, findutils (>= 4.4.0-2ubuntu2)
Suggests: locales, glibc-doc
Conflicts: libterm-readline-gnu-perl (< 1.15-2),
tzdata (< 2007k-1), tzdata-etch, nscd (< 2.9)
Replaces: belocs-locales-bin
Provides: glibc-2.9-1
Description: GNU C Library: Shared libraries
Contains the standard libraries that are used by nearly all programs
on the system. This package includes shared versions of the standard
C library and the standard math library, as well as many others.
Best Answer
They may provide functionally close to the same thing, but it seems 'sudo -i' is lighter weight and keeps some handy back references in your environment.
You can see the extra processes by looking at 'ps auxf' (f gives you a forest view)
sudo -i yields this process tree
sudo su - yields this process tree
Note that they are starting from the same bash process pid, 4482, but that su - seems to spawn another step.)
Your first 'sudo' is already elevating your access level to root. Running su without specifying a username inside sudo changes the current user to root twice.
Another way to investigate this is by running both commands with strace -f.
vs
If you diff those two straces, you'll see more exeve's being run for sudo su -.
One more thing.
sudo -i maintains the extra environment variables set by SUDO.
sudo su - clobbers those variables.