Menu

#111 MSYS2 ssh not finding ssh config or IdentityFile (incorrect tilde expansion when HOME env set)

1.0
open
Alexx83
None
2015-04-19
2014-11-18
Ed
No

STR:
1) Remove/rename old C:\msys64 directory.
2) Set the env variable HOME to "C:\Users\Ed" (replace for your username).
3) Ensure there is no .profile in "C:\Users\Ed" that could interfere.
4) Install msys2-x86_64-20141113.exe
5) Run msys2_shell.bat
6) $ pacman -Sy
7) $ pacman --needed -S bash pacman msys2-runtime
8) Exit the shell.
6) Run msys2_shell.bat
7) $ ssh people.mozilla.org -v

OpenSSH_6.7p1, OpenSSL 1.0.1j 15 Oct 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to people.mozilla.org [63.245.214.133] port 22.
debug1: Connection established.
Could not create directory '/home/Ed/.ssh'.
...

8) $ ssh people.mozilla.org -v -F ~/.ssh/config

OpenSSH_6.7p1, OpenSSL 1.0.1j 15 Oct 2014
debug1: Reading configuration data /c/Users/Ed/.ssh/config
debug1: /c/Users/Ed/.ssh/config line 64: Applying options for *
debug1: Connecting to people.mozilla.org [63.245.214.133] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/Ed/.ssh/foo_rsa type -1
...

9) $ ls -al ~/.ssh/config
-rw-r--r-- 1 Ed None 2072 Oct 29 12:11 /c/Users/Ed/.ssh/config

Expected result:
ssh successfully loads the config from ~/.ssh/config (which has an absolute path of /c/Users/Ed/.ssh/config).
When passed the config file using -F, ssh successfully finds the ssh key, which is referenced in the config as "~/.ssh/foo_rsa" (which has absolute path /c/Users/Ed/.ssh/foo_rsa).

Actual result:
ssh doesn't find the config at ~/.ssh/config, and can be seen trying to create a directory at "/home/Ed/.ssh".
When passed the config file using -F, ssh incorrectly expands "~/.ssh/foo_rsa" to "/home/Ed/.ssh/foo_rsa" rather than "/c/Users/Ed/.ssh/foo_rsa".

tl;dr: For some reason MSYS2's ssh expansion of "~" doesn't take into account HOME, but the |ls -al| in step 9 finds it with no problems.

Related

Tickets: #111

Discussion

1 2 > >> (Page 1 of 2)
  • Ed

    Ed - 2014-11-18

    Sorry my copy/pasting and numbering leaves a lot to be desired.
    The correct steps prior to the ssh commands themselves, are:

    1) Uninstall previous copy of MSYS2 and delete C:\msys64 directory if present.
    2) Set the env variable HOME to "C:\Users\Ed" (replace for your username).
    3) Ensure there is no .profile in "C:\Users\Ed" that could interfere.
    4) Install msys2-x86_64-20141113.exe
    5) Run msys2_shell.bat
    6) $ pacman -Sy
    7) $ pacman --needed -S bash pacman msys2-runtime
    8) Exit the shell.
    9) Run msys2_shell.bat
    10) $ pacman -Su
    11) $ pacman -S openssh
    ...

     
  • Ed

    Ed - 2014-11-18

    Adding the following to /etc/fstab resolves the above issue:

    C:/Users/Ed /home/Ed ntfs binary,posix=0,user 0 0

    However:
    1. This should be set up as part of msys2 install (/as an additional task in /etc/post-install/)
    2. Adding that mount means that the "wrong" path is output ("/home/Ed" instead of the expected "/c/Users/Ed") for:

    $ cd ~
    $ pwd
    /home/Ed

    ...and also performing a |cd /c/Users/Ed| shows the prompt as "Ed@machine /c/Users/Ed" instead of "Ed@ed-laptop ~".

     

    Last edit: Ed 2014-11-18
  • Escoban

    Escoban - 2014-11-24

    I can confirm this bugging bug.

     
  • Alexx83

    Alexx83 - 2014-12-02

    From the OpenSSH README:

    Please note that OpenSSH does never use the value of $HOME to
    search for the users configuration files! It always uses the
    value of the pw_dir field in /etc/passwd as the home directory.
    If no home diretory is set in /etc/passwd, the root directory
    is used instead!
    
     
    • Escoban

      Escoban - 2014-12-02

      So if understood correctly creating a file ~/etc/passwd with pw_dir=~/.ssh resolves the issue?

      Le 02/12/2014 12:14, Alexx83 a écrit :

      From the OpenSSH README:

      |Please note that OpenSSH does never use the value of $HOME to search
      for the users configuration files! It always uses the value of the
      pw_dir field in /etc/passwd as the home directory. If no home diretory
      is set in /etc/passwd, the root directory is used instead!|


      [tickets:#111] http://sourceforge.net/p/msys2/tickets/111 MSYS2 ssh
      not finding ssh config or IdentityFile (incorrect tilde expansion when
      HOME env set)

      Status: open
      Milestone: 1.0
      Created: Tue Nov 18, 2014 12:42 PM UTC by Ed Morley
      Last Updated: Mon Nov 24, 2014 03:37 PM UTC
      Owner: nobody

      STR:
      1) Remove/rename old C:\msys64 directory.
      2) Set the env variable HOME to "C:\Users\Ed" (replace for your username).
      3) Ensure there is no .profile in "C:\Users\Ed" that could interfere.
      4) Install msys2-x86_64-20141113.exe
      5) Run msys2_shell.bat
      6) $ pacman -Sy
      7) $ pacman --needed -S bash pacman msys2-runtime
      8) Exit the shell.
      6) Run msys2_shell.bat
      7) $ ssh people.mozilla.org -v

      OpenSSH_6.7p1, OpenSSL 1.0.1j 15 Oct 2014
      debug1: Reading configuration data /etc/ssh/ssh_config
      debug1: Connecting to people.mozilla.org [63.245.214.133] port 22.
      debug1: Connection established.
      Could not create directory '/home/Ed/.ssh'.
      ...
      

      8) $ ssh people.mozilla.org -v -F ~/.ssh/config

      OpenSSH_6.7p1, OpenSSL 1.0.1j 15 Oct 2014
      debug1: Reading configuration data /c/Users/Ed/.ssh/config
      debug1: /c/Users/Ed/.ssh/config line 64: Applying options for *
      debug1: Connecting to people.mozilla.org [63.245.214.133] port 22.
      debug1: Connection established.
      debug1: key_load_public: No such file or directory
      debug1: identity file /home/Ed/.ssh/foo_rsa type -1
      ...
      

      9) $ ls -al ~/.ssh/config
      -rw-r--r-- 1 Ed None 2072 Oct 29 12:11 /c/Users/Ed/.ssh/config

      Expected result:
      /ssh successfully loads the config from ~/.ssh/config (which has an
      absolute path of /c/Users/Ed/.ssh/config).
      / When passed the config file using -F, ssh successfully finds the ssh
      key, which is referenced in the config as "~/.ssh/foo_rsa" (which has
      absolute path /c/Users/Ed/.ssh/foo_rsa).

      Actual result:
      /ssh doesn't find the config at ~/.ssh/config, and can be seen trying to
      create a directory at "/home/Ed/.ssh".
      / When passed the config file using -F, ssh incorrectly expands
      "~/.ssh/foo_rsa" to "/home/Ed/.ssh/foo_rsa" rather than
      "/c/Users/Ed/.ssh/foo_rsa".

      tl;dr: For some reason MSYS2's ssh expansion of "~" doesn't take into
      account HOME, but the |ls -al| in step 9 finds it with no problems.


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/msys2/tickets/111/
      https://sourceforge.net/p/msys2/tickets/111

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/
      https://sourceforge.net/auth/subscriptions

       

      Related

      Tickets: #111

  • Alexx83

    Alexx83 - 2014-12-02

    No. This is about
    /etc/passwd
    file, not ~/etc/passwd

     
    • Escoban

      Escoban - 2014-12-02

      Ok. So you say that setting the msys2folder/etc/passwd file as indicated solves the problem?

      Should msys2 then be setup like this by default? (In case the user don't have write access to that folder.)

       
  • Alexx83

    Alexx83 - 2014-12-02

    We two-tree weeks ago migrate from /etc/passwd to new Cygwin account mapping scheme. So NO we will never back to /etc/passwd. If you need it you need create it yourself.
    Or try add to /etc/fstab line:

    C:\Users /home
    
     
  • Matthieu Vachon

    Matthieu Vachon - 2014-12-02

    Hi Ed,

    Previously, I was using /etc/passwd to change my user's home. Now that file /etc/passwd is not used anymore, I moved to mounting my Windows user home directory (C:/Users/movachon) to /home/movachon.

    Here the steps:

    1. Add a new line in /etc/fstab to mount C:/Users/movachon/ to /home/movachon. Here my own line: C:/Users/movachon /home/movachon ntfs noacl,binary,posix=1,user 0 0

      I used noacl because when acl was used (which is the default if I remember correctly, I had some problems).

    2. Create directory /home/movachon in msys2 root filesystem: mkdir -p /home/movachon.

    3. Mount the new mount point using mount -a

    4. Check that it is mounted correctly using mount. You should see your Windows user home directory in the list, something like: C:/Users/movachon on /home/movachon type ntfs (binary,noacl,user).

    5. Change your HOME env variable to point to /home/movachon.

    This worked for me. Obviously, change movachon with your username which I think is Ed.

     
    • Alexx83

      Alexx83 - 2014-12-02

      MSYS mount by default with "noacl".
      You can mount /home for all users to Windows home folder in /etc/fstab:

      C:\Users /home
      

      And you don't need HOME environment variable anymore

       
      • Escoban

        Escoban - 2014-12-03

        Thank you Alex, works perfectly now.

         
  • Matthieu Vachon

    Matthieu Vachon - 2014-12-02

    Interesting, thanks for the clarifications :)

     
  • Alexx83

    Alexx83 - 2014-12-03
    • status: open --> closed
    • assigned_to: Alexx83
     
  • Ed

    Ed - 2014-12-03

    I think there's still a missing initial install step or at the least documentation piece here - this "just works" with MSYS1, but not MSYS2 - but I'll open a new ticket for those if you prefer...

     
  • Alexx83

    Alexx83 - 2014-12-03
    • status: closed --> open
     
  • Alexx83

    Alexx83 - 2014-12-03

    What do you mean? MSYS2 is not MSYS1 fork, it new implementation of MSYS on top of recent Cygwin.

     
    • Escoban

      Escoban - 2014-12-04

      I suppose he means that it should not be the user's duty to mount these
      directories to make ssh work, but it should do so out of the box.

       
  • Alexx83

    Alexx83 - 2014-12-04

    By default used /home directory inside MSYS installation folder. I will not change it to use Windows folder by default sorry.

     
    • Escoban

      Escoban - 2014-12-04

      Ok, so a good workaround may be symlinking your dotfile folders into the msys home dir ?

       
  • Alexx83

    Alexx83 - 2014-12-04

    If you need have home directory in Windows users directory you have 2 ways:

    1. Add to /etc/fstab:
      C:\Users /home
      and remove home directory from MSYS folder

    2. Create native Windows symlink for home directory. Cygwin symlinks not supported in MSYS2.

     
    • Escoban

      Escoban - 2014-12-04

      Ok.That the home dir is not that of the user but that in the msys2 folder likely will continue to confuse a lot of users, so that you should you stress it somewhere on your homepage.

       
  • Ed

    Ed - 2014-12-04

    I'm away for work at the moment, so will have to wait until I'm back to dig into the suggested workaround more - but my main point was that the current behaviour involves manual steps (which could potentially be avoided if the MSYS2 installer set things up either by having an advanced mode with prompts, or if it just check the env HOME value and adjusted fstab accordingly). Even if you didn't want to do that, this issue could still be avoided by some wiki/docs changes (ultimately I only filed this bug report because the behaviour was non-obvious and non-documented on the MSYS2 side).

     
    • Escoban

      Escoban - 2014-12-04

      But somehow the home dir is also all over the place because bash_profile is
      loaded from the Windows home Directory. That's why one doesn't expect .ssh
      to have to linger in the Msys2 folder.

       
  • Alexx83

    Alexx83 - 2014-12-06

    There are changes in
    https://cygwin.com/preliminary-ug/ntsec.html
    about home directory and nsswitch.conf

    Read it.

     
  • voidpointer

    voidpointer - 2015-03-15

    Sorry to dig up and old issue but I just burned like 3 hours trying to hunt down why my HOME environment variable was not working with SSH.

    I utilize msys2 with Git on Windows (the msysgit project is using this new approach). I keep my cygwin home directory in dropbox on some distant directory on my drive, like so:

    /e/Dropbox/Robert/Development/Home/Robert
    

    I map HOME to this in my Windows System Environment Variables:

    setx HOME /e/Dropbox/Robert/Development/Home/Robert
    

    When I use git to fetch a clone over SSH or use SSH directly, I expect the following .ssh directory to be utilized:

    ~/.ssh
    

    However this is not the case, it is looking for '/home/Robert/.ssh' which does not exist on my system.

    It seems there is a special case for SSH but everything else properly uses $HOME. I wish it were more obvious that the user has to manually go into C:\msys32\home and run this on Windows 7:

    mklink /D Robert "E:\Dropbox\Robert\Development\Home\Robert"
    

    Could you automate this in the installer? I see two practical approaches:

    1. Look for $HOME already defined in the environment and map that directory to /home via fstab
    2. Ask the user what directory to use (maybe even try #1 first, and on failure do this step) and then map that in fstab.

    Either way I agree this should be automated. If I use this tooling at work, I am going to have 20 very confused and upset co-workers because none of them are linux developers, they only use msys as a "means to an end" for git tooling.

     
1 2 > >> (Page 1 of 2)