我正在尝试在Windows XP机器上配置GIT,但是SSH一直在非常奇怪的地方创建和查找公共/私有密钥对,例如/.ssh/id_rsa。
是否有GIT安装的配置文件可以让我将其切换到我的主目录或其他用户定义的位置?默认情况下,它会在//. ssh/id_rsa处创建新的密钥对,但这会给我带来错误“无法创建目录'//.ssh'”。而当我能够找到一个可以创建它的目录时,GIT也不会在那里查找。
我找到了如何手动设置Windows XP中的主目录:
要通过命令提示符执行相同操作,请执行以下操作:
setx HOME "your\path\to\home"
(请注意后缀x-这用于持久化更改)
%HOME%=C:\Users\[账户名称]\AppData\Roaming\SPB_16.6
或 C:\SPB_data
设置为家目录,但出于某些原因,我不想更改它。然后在 /etc/nsswitch.conf
文件中修改的方法真的有所帮助。像下面这行设置就可以让 ssh-keygen 设置默认位置为 %USERPROFILE%
:db_home: /%H
- Seagal82使用which ssh
命令检查你是否使用的是/usr/bin/ssh
或其他可能由于意外安装而被替换的版本。
在我的情况下,在安装rsync
之后,Chocolatey替换了我的ssh。 运行choco uninstall rsync
后,我的SSH又能正常工作了。
HOME
环境变量已经正确设置:$ echo $HOME
C:\Users\craibuc
然而,尝试连接测试github的ssh
访问失败:
$ 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).
由于某些原因,ssh
尝试访问 C/.ssh
。
当我使用 setx HOME /c/users/craibuc
设置变量并重新启动 shell 后,我能够连接成功:
$ 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.
当我使用一个设置用户配置文件到网络驱动器(在这种情况下映射到Z:
)的域策略的机器时,我遇到了同样的问题。
当尝试从Powershell执行任何操作时,我会收到类似于此的消息。设置home
PATH变量没有帮助。
git clone ssh://myusername@mydomain.com: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.
/z/.ssh
等是从shell指向Z:\.ssh
的有效方式。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
在Windows 7上,只需将您的私钥(id_rsa)放置在C:\ Users \ .ssh文件夹中。如果.ssh文件夹不存在,请创建它。 下载Windows版GIT,进入您的项目目录并执行以下操作: git clone ssh://@/.git
sudo
并重新启动您的shell来解决。我意识到这并没有解决您问题的根本原因,但认为值得提及,因为有人可能会在此处遇到该问题。 - Paul