NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: getlogin, su, and passwd



    Date:        Mon, 5 May 2014 17:46:22 -0400
    From:        Jan Schaumann <jschauma%netmeister.org@localhost>
    Message-ID:  <20140505214622.GS26823%netmeister.org@localhost>

  | That is, passwd(1) will act on the current login name as returned by
  | getlogin(2),

It has been that way for as long as I have been using unix (since 6th
edition, and I think it was the same in 5th - probably as far back as
there has been a passwd commad) - almost 40 years ago now for me.

What's more, it makes some sense - it is changing the password (by default)
for the user who logged in.

It is perhaps less obvious that it is correct this way when you use su to
switch (supposedly temporarily) to a new random user, but if the su target
is root, almost no-one is surprised by this behaviour, in fact, most would be
shocked if it proceeded to attempt to change root's password.

If the intent if the "su" was to actually become a new user, then using
"login" instead (which shells used to treat as "exec login, though I'm not
sure if that persists today - if not, run it that way) is the correct
approach.   Using "su" should mean that it is still really you (as the
user can return to your shell at any time).

If this is weird, just get into the habit of always giving the desired user
name on the passwd command.

kre



Home | Main Index | Thread Index | Old Index