SSH正在寻找Windows上公钥/私钥对的错误位置

问题描述 投票:36回答:7

我正在尝试在我的Windows XP机器上配置GIT,但是SSH一直在非感性的地方创建和查找公钥/私钥对,例如/.ssh/id_rsa

在GIT安装Windows中是否有配置文件,我可以将其切换到我的主目录或其他用户定义的位置?默认情况下,它提供了在//.ssh/id_rsa创建新密钥对,但这给了我错误“无法创建目录'//.ssh'。”当我能够找到一个可以创建它的目录时,GIT就不会看到它。

git github ssh-keys
7个回答
65
投票

想出了如何在Windows XP中手动设置我的主目录:

  1. 右键单击“我的电脑”
  2. 选择“高级”选项卡
  3. 单击“环境变量”按钮
  4. 在“系统变量”部分下,单击“新建”
  5. 在“变量名称”中输入“home”。
  6. 在“变量值”中输入您的配置文件的路径。

要通过命令提示符执行相同操作:

setx HOME "your\path\to\home"

(请注意后缀x - 这用于保持更改)


8
投票

来自MSYS2的Recommended方法是将db_home中的/etc/nsswitch.conf设置为您的主目录。

感谢@VarunAgw在正确的方向为pointing

Git-for-Windows包括env中的db_home,它应该读取你的HOME bash变量,但是,它是unreliable


3
投票

检查which ssh,看看你是否正在使用/usr/bin/ssh或其他可能已经意外安装的东西。

在我的情况下,安装rsync后,我的ssh被Chocolatey取代。运行choco uninstall rsync后,我的SSH再次运行。


2
投票

我在Windows 7上遇到了类似的问题.HOME环境变量似乎设置正确:

$ echo $HOME
C:\Users\craibuc

但是,尝试连接到测试github的ssh访问失败:

$ ssh -Tv [email protected]
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).

出于某种原因,ssh试图访问C/.ssh

当我使用setx HOME /c/users/craibuc设置变量并重新启动shell时,我能够连接:

$ ssh -T [email protected]
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
投票

当使用具有域策略的计算机将用户配置文件设置为网络驱动器(在本例中映射到Z:)时,我遇到了同样的问题。

当试图从Powershell做任何事情时,我会收到这样的消息。设置home PATH变量没有帮助。

git clone ssh://[email protected]:1234/myproject
Cloning into 'myproject'...
Could not create directory '/z/.ssh'.
The authenticity of host '[mydomain.com]:1234 ([1.1.1.1]:1234)' can't be established.
RSA key fingerprint is 00:11:22:33:$4:55:66:77:88.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/z/.ssh/known_hosts).
Permission denied (publickey).

Please make sure you have the correct access rights
and the repository exists.

当我从git bash克隆时它很好,因为/z/.ssh等是从shell中指向Z:\.ssh的有效方法。


0
投票

ln -s /c/Users/rofrol/.ssh /home/rofrol/为我工作。

这没有:

$ 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

可能是因为这个:

SSH将需要/ home / $ USER

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


-3
投票

在Windows 7上只需将您的私钥(id_rsa)放在C:\ Users \ .ssh文件夹中如果.ssh文件夹不存在则只需创建它。下载GIT for Windows,进入项目目录并执行git clone ssh://@/.git

© www.soinside.com 2019 - 2024. All rights reserved.