[sudo-users] why are my ~/.bashrc aliases not honoured by sudo ?
Shriramana Sharma
samjnaa at gmail.com
Tue Sep 16 05:28:48 EDT 2008
Hello I'm new to this list, and am only moderately knowledgeable
technically, so please be patient my ignorance.
In both my /home/samjnaa/.bashrc and /root/.bashrc I have the alias rm =
'rm -i' to prevent me from deleting stuff accidentally. (I can always
use -f to override the -i if I'm really sure.) But I find that though
both the user and root shells honour this alias, it is not honoured by
sudo. See:
[samjnaa:~] cd /tmp
[samjnaa:/tmp] touch foo
[samjnaa:/tmp] rm foo
rm: remove regular empty file `foo'? n
[samjnaa:/tmp] sudo -i
[sudo] password for samjnaa:
[root:~] rm /tmp/foo
rm: remove regular empty file `/tmp/foo'? n
[root:~] exit
logout
[samjnaa:/tmp] sudo rm /tmp/foo
[samjnaa:/tmp]
Also with a sub-shell:
[samjnaa:/tmp] touch foo
[samjnaa:/tmp] sudo bash -c 'rm foo'
[samjnaa:/tmp]
I don't get it. IIRC sudo runs the command with the process's uid/gid=0.
To execute the command, bash is needed anyhow. So whether bash reads the
user's .bashrc or root's .bashrc, it must see and obey this alias. Why
does this not happen? Does bash not see the rm command at all?
Thanks.
Shriramana Sharma.
More information about the sudo-users
mailing list