Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 8 Jan 2000 08:28:44 +0100 (CET)
From:      Oliver Fromme <olli@dorifer.heim3.tu-clausthal.de>
To:        freebsd-questions@FreeBSD.ORG
Subject:   Re: su and aliases question
Message-ID:  <200001080728.IAA04151@dorifer.heim3.tu-clausthal.de>
In-Reply-To: <854tm0$1pfa$1@atlantis.rz.tu-clausthal.de>

next in thread | previous in thread | raw e-mail | index | archive | help
Jonathon McKitrick <jcm@dogma.freebsd-uk.eu.org> wrote in list.freebsd-questions:
 > OK, just to make sure: when i have logged into my user account, it
 > executes all those zsh scripts, assuming i run from a console login.  Now,
 > when i run 'su -m' it should simply give me the UID of root and leave
 > everything alone, correct?

Not quite.  This is how "su" works:

In UNIX, it is not possible to change the UID of a running non-
root process to root, in general.  (There are exceptions, but
they don't matter in this context.)  Therefore, the "su"
command cannot simply change the UID of your existing shell to
root.

Instead, "su" is a set-uid-root binary (type ``ls -l =su'' and
see the s-bit).  When it is exec'ed, it runs as root rigth from
the start.  It then asks you for the root password -- if it
doesn't match, "su" exits and you're back at your normal user
shell.  If you entered the right password, "su" in turn exec's
a new shell, which inherits owenerships from the parent "su",
i.e. the new shell is running as root.  When you exit this root
shell, you're again back at your normal user shell.

The command line options of "su" specify how to start that new
shell exactly (see ``man su'' for a lot of details).  If you
use the "-m" option, it will ignored root's login shell and use
the login shell of the user who invoked "su", and it will not
change any environment variables, neither the cwd.

 > Does it start a new invocation of zsh?

Yes.

 > I just
 > don't understand why none of the aliaes or other commands are executed
 > when i 'su -m'.

Commands from your ~/.zshenv _should_ be executed.  That file
will be read by _every_ invokation of zsh, no matter what
(unless you have a very strange, non-standard zsh installa-
tion).

Also, commands from your ~/.zshrc should be executed for every
invokation of an interactive zsh (which a root shell clearly is
when executed from "su").

If it doesn't work for you, I'd recommend to place a few "echo"
commands at appropriate places, to find out what's wrong.
For example, insert the line

   echo "starting .zshrc, PID = $$, EUID = $EUID"

right at the top of your ~/.zshrc, and append the line

   echo "finished .zshrc"

at the end.  You can do similar things with your other ~/.z*
startup scripts, just for debugging (don't forget to remove
them afterwards, because it might confuse programs such as rcp
and scp).

The above "echo" commands will help you find out if the files
are read by your root shell at all.

Regards
   Oliver

-- 
Oliver Fromme, Leibnizstr. 18/61, 38678 Clausthal, Germany
(Info: finger userinfo:olli@dorifer.heim3.tu-clausthal.de)

"In jedem Stück Kohle wartet ein Diamant auf seine Geburt"
                                         (Terry Pratchett)


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200001080728.IAA04151>