Behaviour of su(1)

Frédéric Perrin frederic.perrin at resel.fr
Fri Oct 31 12:00:18 PDT 2008


Hello,

When I « su - » to root (after being logged in as my normal user), the
LOGNAME env variable is still set to my previous user, as in :

,----
| fred at chameau:~% /usr/bin/su -l
| Password:
| root at chameau:~# echo $USER - $LOGNAME
| root - fred
`----

As far as I can tell, this contradicts the fine manual that says :

,----
| -l      Simulate a full login.  The environment is discarded except for
|         HOME, SHELL, PATH, TERM, and USER.
`----

So I would have expected LOGNAME to be either empty or set by some shell
startup script to be root. So, why is LOGNAME still equal to my previous
user ? (and where is it set ? « grep -r LOGNAME /etc » doesn't turn up
anything...)

This is an issue because emacs, for instance, uses $LOGNAME to load the
init-file. I could always add « export LOGNAME=root » to my shell
startup file, but this doesn't quite feel right...

GNU su (as it is ocnfigured in Debian at least) resets LOGNAME to root
in the same situation. (and by the way, GNU su seems broken : if I « gsu
-l root », I always get a 'Password incorrect' answer).

As a side question, is it considered bad practice to set root's shell
and locales to something else then the default ?

-- 
Fred


More information about the freebsd-questions mailing list