Output from “mkpasswd -c” differs with “cat /etc/passwd | grep $USER”

0

I have noticed that my $HOME becomes different from ~ after running some SSH commands. I would like to understand what is causing this difference.

I am using Cygwin's SSH:

$ which ssh
/usr/bin/ssh

This is what I see:

$ echo $HOME
/c/Users/axxx

$ echo ~
/home/axxx

While investigating this I noticed that /etc/passwd | grep $USER differs from mkpasswd -c. I expected them to be the same, and when $HOME and ~ become distinct, ~ equals the home directory corresponding to the output of mkpasswd -c while $HOME equals the entry for the home directory in /etc/passwd.

In addition to the location of the home directory, the entries for User ID and Group ID are also distinct. There is a difference in the username also, in /etc/passwd, I noticed my username is of the form dxxx+axxx where dxxx is my machine name, while in the output of mkpasswd -c, my username is simply axxx.

[Added Later]

I noticed ~ is picked up from db_home from /etc/nsswitch.conf and $HOME corresponds to the entry in /etc/passwd.

Arin Chaudhuri

Posted 2016-07-25T17:05:31.460

Reputation: 101

Take a look at /etc/profile. It explains exactly how HOME is set. – DavidPostill – 2016-07-25T17:47:44.533

Thanks I noticed it uses /usr/bin/install. Any idea where mkpasswd -c it getting its data from? – Arin Chaudhuri – 2016-07-25T20:13:29.773

No idea. You could look at the source code ... – DavidPostill – 2016-07-25T20:18:19.177

Most from the windows info for the current user. – matzeri – 2016-07-25T20:30:40.467

No answers