When I tried to "sudo su" instead of "sudo su -" after having been logged in as root and su-ing to another user, it tries to sudo me as the new user, but via root...
When I type
env, it shows still username=root in the environment. Is sudo not looking at the currently logged in user, but at the enviroment parameters?
[oracle@tst-01]$ sudo su grid Sorry, user oracle is not allowed to execute '/bin/su grid' as root on tst-01.testdomain.com. [oracle@tst-01]$ env HOSTNAME=tst-01.testdomain.com TERM=xterm SHELL=/bin/bash HISTSIZE=1000 QTDIR=/usr/lib64/qt-3.3 USER=oracle SUDO_USER=ujjain USERNAME=root MAIL=/var/spool/mail/ujjain PATH=/usr/lib/oracle/10.2.0.4/client64/bin:/usr/lib/oracle/10.2.0.4/client64/bin:/sbin:/bin:/usr/sbin:/usr/bin PWD=/home/ujjain LANG=en_US.utf8 HOME=/opt/apps/oracle SUDO_COMMAND=/bin/su SHLVL=2 LOGNAME=oracle CVS_RSH=ssh LESSOPEN=|/usr/bin/lesspipe.sh %s SUDO_GID=3000 ORACLE_HOME=/usr/lib/oracle/10.2.0.4/client64 G_BROKEN_FILENAMES=1 _=/bin/env [oracle@tst-01 ujjain]$ sudo su - grid [grid@tst-01 ~]$
It seems that sudo su newuser should also work if sudo would only be looking if the currently logged in user has sudo rights to sudo to the new user. What is sudo su doing and why is it important for non-root users to use sudo su - newuser with the hyphen?