While creating an oracle installation script, I noticed that upon issuing the command: "su -login -command 'env' oracle" that the environment was not correctly set (resulting in the database not starting). I tried this with a variety of commands and users and have noticed the same result with /bin/su on at least 4 Gentoo 1.4 boxes. On testing the command on RedHat, the 'su' command completes as expected. Reproducible: Always Steps to Reproduce: 1. Login as root. 2. /bin/su -l -c 'whoami' foobar Actual Results: root Expected Results: foobar
If this bug is a duplicate - I apologise. Searching for 'su' returns many, many results (which I scanned) :(
what if you use `su - <username>` ? the manpage for su does not list '--login' as a valid option
I normally use 'su - ', but this does not work either (ironically I used --login in my summary, etc. to aviod confucsion). The manpage does not list this, but the info page does. From 'info su': `-' `-l' `--login' Make the shell a login shell. This means the following. Unset all environment variables except `TERM', `HOME', and `SHELL' (which are set as described above), and `USER' and `LOGNAME' (which are set, even for the super-user, as described above), and set `PATH' to a compiled-in default value. Change to USER's home directory. Prepend `-' to the shell's name, intended to make it read its login startup file(s). From my experience with Linux From Scratch, if I remember correctly, 'su' is contained in more than one GNU utils "package". Perhaps this version does not support the '-' option? This might also explain the differences between the info and manpages? This version seems to come with shadow-utils. The other seems to be from sh-utils (RedHat also uses the sh-utils version). A quick look at the output from ldd for /bin/su (both versions) shows that they both are linked to the same libraries. Hope this extra info (no pun intended) helps.
The info page is from sh-utils (coreutils.info), which have the options for the su we do not use. Unfortunately the info file have other usefull info, so nuking it is not an option I would like to consider. And su we use supporting pam, make it more secure than the one from sh-utils. Please use 'man su' for info on su. I am marking this as wont fix, as there is no clear middle way :(