getpwuid vs. getpwnam

Bob Proulx bob at
Sat Dec 4 16:43:41 EST 2004

John Cecere wrote:
> Please respond directly.
> [...]
> I would think that it would make more sense to use the home directory of 
> the intended user. Using the user name (not the uid) as the basis of 
> determining the home directory of the user is something that unix 
> programs have done since I started working with unix 20 years ago.

Uhm... Actually unix systems don't really care about the name of the
user account very much.  Almost everything uses the user id number.

> If you look at other commands in unix (e.g. telnet, rlogin, ftp,
> etc.), they all use the username as the basis for determining the
> home directory for their configuration files, which is why I've
> never had a problem with them.

After giving this more thought I won't object to the use of $HOME in
the client side only use of finding the identity key files.  I would
have to change some things but it is not a huge deal as long as it was
called out in the update notes.  Conceptually it is no different than
the following.

  alias ssh='ssh -i $HOME/.ssh/id_rsa'

> There's another thing that puts a wrench into this. What would
> happen if you didn't list root as the first entry in /etc/passwd ?
> There's nothing that says that you have to. If your alternate root
> account was listed before root in /etc/passwd, ssh would always use
> the alternate root account's home directory, even if you logged in
> as root itself.  So with the current scheme that ssh employs, order
> becomes important in /etc/passwd when it shouldn't be.

This is not specific to ssh.  Everything else uses that paradigm too.
Think of what 'ls -l' will show you in that case too.  Again there is
no real significance to the name.  It is the uid that the system cares
about.  'ls -ln' will still show uid 0 as owning system files even if
you make the account name something different.  This is why we
differentiate between the 'root' user as a name and the superuser as a

> Now granted, most people don't go around mixing up their /etc/passwd
> and moving the root entry elsewhere,

Sometimes they do and get confused by it.  I just had an extended
email exchange with someone who had done just that and was confused as
to why 'ls -l' showed them an alternate superuser account over the
'root' account.


More information about the openssh-unix-dev mailing list