msys2 / MSYS2-packages

Package scripts for MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
1.3k stars 489 forks source link

[openssh] #2637

Closed james-duvall closed 3 years ago

james-duvall commented 3 years ago

Hi, I'm having an issue with ssh not finding my home directory. It seems to be looking in /home when it should be looking in /c/Users/

I have $HOME set to /c/Users/duvall_jw, cd ~ seems to work correctly in bash, and other programs such as vim and nano don't have any issues finding my home directory or loading their dotfiles.

duvall_jw@Laptop-135 MSYS /
$ echo $HOME
/c/Users/duvall_jw

duvall_jw@Laptop-135 MSYS /
$ cd ~

duvall_jw@Laptop-135 MSYS ~
$ 

Below is the content of ssh -v git@gitlab. You can see that it is looking in /home/duvall_jw.

duvall_jw@Laptop-135 MSYS /
$ ssh -v git@gitlab
OpenSSH_8.7p1, OpenSSL 1.1.1l  24 Aug 2021
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to gitlab [192.168.17.56] port 22.
debug1: Connection established.
debug1: identity file /home/duvall_jw/.ssh/id_rsa type -1
debug1: identity file /home/duvall_jw/.ssh/id_rsa-cert type -1
debug1: identity file /home/duvall_jw/.ssh/id_dsa type -1
debug1: identity file /home/duvall_jw/.ssh/id_dsa-cert type -1
debug1: identity file /home/duvall_jw/.ssh/id_ecdsa type -1
debug1: identity file /home/duvall_jw/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/duvall_jw/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/duvall_jw/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/duvall_jw/.ssh/id_ed25519 type -1
debug1: identity file /home/duvall_jw/.ssh/id_ed25519-cert type -1
debug1: identity file /home/duvall_jw/.ssh/id_ed25519_sk type -1
debug1: identity file /home/duvall_jw/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/duvall_jw/.ssh/id_xmss type -1
debug1: identity file /home/duvall_jw/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.7
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: compat_banner: match: OpenSSH_7.4 pat OpenSSH_7.4* compat 0x04000006
debug1: Authenticating to gitlab:22 as 'git'
debug1: load_hostkeys: fopen /home/duvall_jw/.ssh/known_hosts: No such file or directory
debug1: load_hostkeys: fopen /home/duvall_jw/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:XcNbvfKMTLd1DBwEN1rDx0B0pRl3DJsDEzoqalCNDZQ
debug1: load_hostkeys: fopen /home/duvall_jw/.ssh/known_hosts: No such file or directory
debug1: load_hostkeys: fopen /home/duvall_jw/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: hostkeys_find_by_key_hostfile: hostkeys file /home/duvall_jw/.ssh/known_hosts does not exist
debug1: hostkeys_find_by_key_hostfile: hostkeys file /home/duvall_jw/.ssh/known_hosts2 does not exist
debug1: hostkeys_find_by_key_hostfile: hostkeys file /etc/ssh/ssh_known_hosts does not exist
debug1: hostkeys_find_by_key_hostfile: hostkeys file /etc/ssh/ssh_known_hosts2 does not exist
The authenticity of host 'gitlab (192.168.17.56)' can't be established.
ED25519 key fingerprint is SHA256:XcNbvfKMTLd1DBwEN1rDx0B0pRl3DJsDEzoqalCNDZQ.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])?

As a workaround, I can make ssh work correctly by copying ~/.ssh to /home/duvall_jw/.ssh, but this isn't a great solution since this is the only program using that directory.

Is there possibly some bug where ssh is not reading the environment correctly?

jeremyd2019 commented 3 years ago

It may be reading from getpwent instead. https://cygwin.com/cygwin-ug-net/ntsec.html#ntsec-mapping-nsswitch (your environment would normally only be loaded post-authentication)

For your case, set/add db_home: /c/Users/%U to /etc/nsswitch.conf

james-duvall commented 3 years ago

@jeremyd2019

Wow, thanks for the quick response. This worked perfectly. I will look into the link you posted.

jeremyd2019 commented 3 years ago

You might also be able to use db_home: windows, assuming your user profile is the same as your home directory (it may not be if you are a domain user).

james-duvall commented 3 years ago

Thanks for pointing me to the nsswitch information. This solved my issue. There seems to be inconsistency between how various components of msys2 use environment variables and the nsswitch to find HOME and other user data.

both db_home: windows and db_home: /%H/%U seem to work for me.