最近我一直无法克隆或推送到github,我试图找到根本原因。

这是在窗口上

我有cygwin + git以及msysgit。

安装Msysgit的选项如下:

OpenSSH 从Windows命令提示符中使用Git

这给了我4个环境来尝试使用git:

Windows cmd提示符 Powershell Git Bash Cygwin

不知怎的,我已经设法让自己进入一个位置,当我尝试使用msysgit, cmd.exe或Powershell克隆一个存储库时,我得到以下错误:

> Initialized empty Git repository in
> C:/sandbox/SomeProject/.git/
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> @    WARNING: UNPROTECTED PRIVATE KEY FILE!          @
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> Permissions 0644 for
> '/c/Users/Ben/.ssh/id_rsa' are too
> open. It is recommended that your
> private key files are NOT accessible
> by others. This private key will be
> ignored. bad permissions: ignore key:
> /c/Users/Ben/.ssh/id_rsa Permission
> denied (publickey). fatal: The remote
> end hung up unexpectedly

这是使用我的c:\users\ben\文件夹中的.ssh文件夹,这是msysgit使用的文件夹。我怀疑cygwin工作,因为.ssh文件夹位于其他地方,但我不确定为什么

在Git Bash中,我检查权限:

$ ls -l -a ~/.ssh

这给了我:

drwxr-xr-x    2 Ben      Administ        0 Oct 12 13:09 .    
drwxr-xr-x   34 Ben      Administ     8192 Oct 12 13:15 ..    
-rw-r--r--    1 Ben      Administ     1743 Oct 12 12:36 id_rsa
-rw-r--r--    1 Ben      Administ      399 Oct 12 12:36 id_rsa.pub    
-rw-r--r--    1 Ben      Administ      407 Oct 12 13:09 known_hosts

这些许可显然太宽松了。我不知道他们是怎么变成这样的。

我可以试着改变他们……

$ chmod -v -R 600 ~/.ssh

这告诉我:

mode of `.ssh' changed to 0600 (rw-------)
mode of `.ssh/id_rsa' changed to 0600 (rw-------)
mode of `.ssh/id_rsa.pub' changed to 0600 (rw-------)
mode of `.ssh/known_hosts' changed to 0600 (rw-------)

但这似乎没有效果。我还是得到同样的错误

$ ls -l -a ~/.ssh

产生与以前相同的权限。

更新:

我试图修复这些文件的权限在cygwin,和cygwin报告他们的权限正确,gitbash没有: Alt文本http://cdn.cloudfiles.mosso.com/c54102/app7962031255448924.jpg

关于如何真正修复这些权限,有什么想法吗?


当前回答

我在Windows 10上也遇到了同样的问题,我试图SSH进入一个Vagrant盒子。这似乎是旧OpenSSH版本中的一个bug。对我有用的是:

从http://www.mls-software.com/opensshd.html安装最新的OpenSSH where.exe ssh

(如果使用Powershell,请注意“。exe”)

你可能会看到如下内容:

C:\Windows\System32\OpenSSH\ssh.exe
C:\Program Files\OpenSSH\bin\ssh.exe
C:\opscode\chefdk\embedded\git\usr\bin\ssh.exe

注意,在上面的示例中,最新的OpenSSH位于路径的第二个位置,因此不会执行。

更改顺序:

右键单击Windows按钮->设置->“编辑系统环境变量” 在“高级”选项卡上单击“环境变量…” 在“系统变量”下编辑“路径”。 选择“C:\Program Files\OpenSSH\bin”并“向上移动”,使其出现在顶部。 单击OK 重新启动控制台,以便应用新的环境变量。

其他回答

我的系统有点混乱的bash/cygwin/git/msysgit/也许-更多…

Chmod对密钥或配置文件没有影响。

然后我决定从Windows操作系统入手,这是可行的。

Right-Click the file whose permission needs fixing. Select Properties. Select the Security tab. Click Advanced near the bottom. Click Change, next to Owner near the top. Type "My-Awesome-Username" (obviously change that to your current Windows username), and click Check Names, then OK. Under Permission entries:, highlight each user that isn't "My-Awesome-Username", and select Remove. Repeat this until "My-Awesome-Username" is the only one left. Select "My-Awesome-Username", and click Edit below. Make sure the Type: at the top is set to Allow, and then tick the checkbox next to Full control. Hit OK, Apply, OK, OK. Give it another try now...

似乎有时候mock-bash不能控制文件的所有权。它特别奇怪,因为它是从模拟bash脚本生成的。图。

对于使用这里找到的Git的Windows 7(它使用MinGW,而不是Cygwin):

在windows资源管理器中,右键单击id_rsa文件并选择属性 选择安全选项卡并单击编辑… 选中除管理员外的所有组的“完全控制”旁边的“拒绝”框 重试Git命令

cygwin的chmod有一个bug,请参考:

https://superuser.com/questions/397288/using-cygwin-in-windows-8-chmod-600-does-not-work-as-expected

chgrp -Rv Users ~/.ssh/* 
chmod -vR 600 ~/.ssh/id_rsa

MAC用户:

在终端中输入以下命令更改密钥对文件的设置:

chmod og-r *filename.pem*

(确保您在正确的目录中,或命令中的路径文件名正确)。

我可以通过做两件事来解决这个问题,尽管你可能不需要做第一步。

从cygwin ssh.exe和所有cyg*.dll复制到Git的bin目录(这可能不是必要的,但这是我采取的步骤,但这本身并没有解决问题) 按照以下步骤操作:http://zylstra.wordpress.com/2008/08/29/overcome-herokus-permission-denied-publickey-problem/ 我添加了一些细节到我的~/。ssh /配置文件:

主机heroku.com 主机名:heroku.com 端口22 IdentitiesOnly是的 IdentityFile ~ / . ssh / id_heroku TCPKeepAlive是的 用户布兰登

我必须使用用户作为我的电子邮件地址heroku.com 注意:这意味着你需要创建一个密钥,我按照这个来创建密钥,当它提示输入密钥的名称时,一定要指定id_heroku http://help.github.com/win-set-up-git/

然后添加键: Heroku键:添加~/.ssh/id_heroku.pub