According to man sudo
sudo -i
starts a login shell and should in my understanding read/source ~/.profile
, i.e. /root/profile
or [non-root user home/.profile
and /etc/profile
. Adding aliases, e.g. alias ll='ls -la'
to both files doesn't make the alias available in the shell started by sudo -i
. If I run bash
in the shell stared by sudo -i
aliases are available.
I already figured out to put aliases in /etc/profile.d/00-aliases.sh
in https://askubuntu.com/questions/810730/how-to-share-bash-aliases-between-non-root-user-bash-and-shell-opened-by-sudo. Here I just want to know why the expected behaviour doesn't occur.
I reported this as a sudo bug on launchpad.net, but now I'm not sure whether this might be a tricky aspect of expected behaviour. The way man sudo
describes -i
is too trivial anyway.
-i: Run the shell specified by the target user's password database entry as a login shell.
bash:A login shell is one whose first character of argument zero is a -, or one started with the --login option.
sudo just sets the dash as the first character in the shell's name when running it./root/.*{profile,login}
and/etc/profile*
. And thebashrc
files.