SSH is looking in the wrong place for the public/private key pair on Windows

后端 未结 7 703
眼角桃花
眼角桃花 2020-12-04 18:19

I\'m trying to configure GIT on my Windows XP machine, but SSH keeps creating and looking for the public/private key pair in non-sensical places, e.g. /.ssh/id_rsa

I

相关标签:
7条回答
  • 2020-12-04 18:29

    ln -s /c/Users/rofrol/.ssh /home/rofrol/ worked for me.

    This did not:

    $ echo $HOME
    /c/Users/rofrol
    
    $ cat ~/nsswitch.conf
    db_home: /c/Users/rofrol
    
    $ cat /home/rofrol/nsswitch.conf
    db_home: /c/Users/rofrol
    
    $ cat /etc/nsswitch.conf
    # Begin /etc/nsswitch.conf
    
    passwd: files db
    group: files db
    
    db_enum: cache builtin
    
    #db_home: cygwin desc
    db_home: /c/Users/rofrol
    db_shell: cygwin desc
    db_gecos: cygwin desc
    
    # End /etc/nsswitch.conf
    

    Probably because of this:

    SSH will require /home/$USER

    https://github.com/git-for-windows/git/issues/736#issuecomment-215123009

    0 讨论(0)
  • 2020-12-04 18:29

    On Windows 7 Just Place your Private Key ( id_rsa ) inside C:\Users\.ssh FOLDER If .ssh Folder doesnt exist just create it. Download GIT for Windows, cd into your Project Directory and do git clone ssh://@/.git

    0 讨论(0)
  • 2020-12-04 18:33

    Figured out how to manually set my home directory in Windows XP:

    1. Right click "My Computer"
    2. Choose the "Advanced" tab
    3. Click the "Environmental Variables" button
    4. Under the "System variables" section, click "New"
    5. In the "Variable name" enter in "home".
    6. In the "Variable value" enter in the path to your profile.

    To do the same via command prompt do :

    setx HOME "your\path\to\home"
    

    ( Please note the suffix x - This is used to persist the change )

    0 讨论(0)
  • 2020-12-04 18:35

    Recommended method from MSYS2 is to set db_home in /etc/nsswitch.conf to your home directory.

    Credit to @VarunAgw for pointing in the right direction.

    Git-for-Windows includes env in db_home, which should read your HOME bash variable, however, it is unreliable.

    0 讨论(0)
  • 2020-12-04 18:37

    Check which ssh to see if you are using /usr/bin/ssh or something else, that might have installed by accident.

    In my case my ssh was replaced by Chocolatey after installing rsync. After running choco uninstall rsync, my SSH was working again.

    0 讨论(0)
  • 2020-12-04 18:39

    I was having a similar problem on Windows 7. The HOME environment variable seemed to be set correctly:

    $ echo $HOME
    C:\Users\craibuc
    

    However, attempts to connect to test github's ssh access failed:

    $ ssh -Tv git@github.com
    OpenSSH_6.6.1, OpenSSL 1.0.1i 6 Aug 2014
    debug1: Connecting to github.com [192.30.252.129] port 22.
    debug1: Connection established.
    Could not create directory 'C/.ssh'.
    debug1: identity file C/.ssh/id_rsa type -1
    debug1: identity file C/.ssh/id_rsa-cert type -1
    debug1: identity file C/.ssh/id_dsa type -1
    debug1: identity file C/.ssh/id_dsa-cert type -1
    debug1: identity file C/.ssh/id_ecdsa type -1
    debug1: identity file C/.ssh/id_ecdsa-cert type -1
    debug1: identity file C/.ssh/id_ed25519 type -1
    debug1: identity file C/.ssh/id_ed25519-cert type -1
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH_6.6.1
    debug1: Remote protocol version 2.0, remote software version libssh-0.6.0
    debug1: no match: libssh-0.6.0
    debug1: SSH2_MSG_KEXINIT sent
    debug1: SSH2_MSG_KEXINIT received
    debug1: kex: server->client aes128-ctr hmac-sha1 none
    debug1: kex: client->server aes128-ctr hmac-sha1 none
    debug1: sending SSH2_MSG_KEX_ECDH_INIT
    debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
    debug1: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
    The authenticity of host 'github.com (192.30.252.129)' can't be established.
    RSA key fingerprint is xx:xx:xx.
    Are you sure you want to continue connecting (yes/no)? yes
    Failed to add the host to the list of known hosts (C/.ssh/known_hosts).
    debug1: ssh_rsa_verify: signature correct
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug1: SSH2_MSG_NEWKEYS received
    debug1: Roaming not allowed by server
    debug1: SSH2_MSG_SERVICE_REQUEST sent
    debug1: SSH2_MSG_SERVICE_ACCEPT received
    debug1: Authentications that can continue: publickey
    debug1: Next authentication method: publickey
    debug1: Trying private key: C/.ssh/id_rsa
    debug1: Trying private key: C/.ssh/id_dsa
    debug1: Trying private key: C/.ssh/id_ecdsa
    debug1: Trying private key: C/.ssh/id_ed25519
    debug1: No more authentication methods to try.
    Permission denied (publickey).
    

    For some reason, ssh was attempting to access C/.ssh.

    When I set the variable using setx HOME /c/users/craibuc and restarted the shell, I was able to connect:

    $ ssh -T git@github.com
    Warning: Permanently added the RSA host key for IP address '192.30.252.130' to the list of known hosts.
    Hi craibuc! You've successfully authenticated, but GitHub does not provide shell access.
    
    0 讨论(0)
提交回复
热议问题