【问题标题】:On win7, cygwin and git bash have different ideas about a file or folder's permission在win7上,cygwin和git bash对文件或文件夹的权限有不同的想法
【发布时间】:2018-01-23 14:18:24
【问题描述】:

在 Cygwin 中,我设置了文件夹“tmp”的权限

$ chmod 600 tmp

$ ls -ld tmp
drw-------+ 1 leecy Users 0 Aug 15 10:56 tmp

但 Git Bash(来自 Git for Windows)有不同的想法 权限:

$ ls -ld ~/tmp
drwxr-xr-x 1 leecy 1049089 0 Aug 15 10:56 /c/cygwin64/home/leecy/tmp/

我已经研究、阅读并尝试了以下帖子中的建议(chgrpchown :Userssetfacl 等),但仍然找不到解决方案:

顺便说一下,这个问题相信是我git clone操作的原因 (使用 SSH)最近停止工作。在上面我是 用测试文件夹tmp 演示问题,但在现实生活中 该文件夹实际上是我的.ssh 和我的git clone 最近开始 失败并出现以下错误:

$ git clone ...
Cloning into 'foo'...
Bad owner or permissions on /home/leecy/.ssh/config
fatal: Could not read from remote repository.

最近可能有一些与 Windows 域相关的更改 与此相关的设置(由公司 IT 人员完成) 问题 - 更改后问题开始浮出水面。

版本:

Cygwin: 2.8.2(0.313/5/3)
Git Bash: git version 2.14.1.windows.1

更新

感谢 Doug Henderson 的建议(见评论)。
我尝试使用命令setfacl -b -k,它确实删除了 额外的非标准 POSIX 权限,但它没有 解决问题。

在使用setfacl -b -k之前

$ getfacl tmp
# file: tmp
# owner: leecy
# group: Users
user::rw-
group::---
other:---
default:user::rwx
default:group::r-x
default:other:r-x

使用setfacl -b -k

leecy@USLEECY-C1 ~
$ setfacl -b -k tmp

leecy@USLEECY-C1 ~
$ getfacl tmp
# file: tmp
# owner: leecy
# group: Users
user::rw-
group::---
other:---

但这并没有帮助

cygwin:

$ ls -ld tmp
drw------- 1 leecy Users 0 Aug 15 10:56 tmp

Git 重击:

$ ls -ld tmp
drwxr-xr-x 1 leecy 1049089 0 Aug 15 10:56 tmp/

更新 2

使用getfacl 我仔细检查了文件所在的组,并且 确实cygwingit bash有两个不同的想法

赛格温

$ getfacl tmp
# file: tmp
# owner: leecy
# group: Users
user::rw-
group::---
other:---

Git 重击

$ getfacl tmp
# file: tmp
# owner: leecy
# group: 1049089 <unknown>
user::rwx
group::r-x
other:r-x

数字1049089 在我的系统中可能意味着Domain Users,但是 cygwin 似乎可以理解这个数字,但git bash 不理解。 我这么说是因为我的 cygwin /etc/group 有这样一行 (这个文件原本不存在,我使用命令创建它 mkgroup -l -d &gt; /etc/group 建议在此 post)

Domain Users:S-1-5-21-1593251271-2640304127-1825641215-513:1049089:

我还尝试了命令chgrpchown。两者都运行没有错误, 但未生效(数字545Users 的组ID cygwin(但不是git bash)理解)

chgrp无效

$ getfacl tmp
# file: tmp
# owner: leecy
# group: 1049089 <unknown>
user::rwx
group::r-x
other:r-x

$ chgrp 545 tmp

$ ls -ld tmp
drwxr-xr-x 1 leecy 1049089 0 Aug 15 10:56 tmp/

$ getfacl tmp
# file: tmp
# owner: leecy
# group: 1049089 <unknown>
user::rwx
group::r-x
other:r-x

chown无效

leecy@USLEECY-C1 MINGW64 ~
$ chown leecy.545 tmp

leecy@USLEECY-C1 MINGW64 ~
$ ls -ld tmp
drwxr-xr-x 1 leecy 1049089 0 Aug 15 10:56 tmp/

leecy@USLEECY-C1 MINGW64 ~
$ getfacl tmp
# file: tmp
# owner: leecy
# group: 1049089 <unknown>
user::rwx
group::r-x
other:r-x

【问题讨论】:

  • cygwin 有一个 git 包。为什么不使用它?
  • 在cygwin中ls显示的权限末尾的+表示存在不适合用户/组/其他、读/写/执行模型的附加权限。您可以使用getfacl cygwin 命令或icacls windows 命令或在文件资源管理器中右键单击属性来显示它们。检查tmp 目录及其父目录的acls。您可能会在其中一个修改预期权限的父级上找到默认 acl。
  • 您还应该检查 git 全局配置的内容。在 cygwin 和 msys2 上,它可能位于 ~/.gitconfig 中。我已将它们配置为彼此相处融洽。 cygwin 和 msys2 使用不同的方法将 windows 内部用户 id 和组 id 转换为 unix 样式名称和数字。比较 /etc/nsswitch.conf 文件以获取线索。
  • @DougHenderson -- 感谢您的建议!我尝试了命令 setfact -b -k 。它确实删除了额外的非标准 POSIX 权限,但并没有解决问题。有关详细信息,请参阅我在问题中的更新。
  • 我还查看了我的~/.gitconfig。我在那里没有看到任何与权限相关的内容。文件中唯一的指令是[user][credential][gui]

标签: git permissions window cygwin git-bash


【解决方案1】:

感谢所有建议(来自 Doug Henerson 和 matzeri)。我的 最初的问题是关于许可的差异 由cygwingit bash 提供,但确实是我想要实现的 是让我的git 再次工作(失败并出现错误

Bad owner or permissions on /home/leecy/.ssh/config

)

感谢 matzeri 的建议。我尝试了cygwin git并意识到 git的错误不是由于 我的~/.ssh~/.ssh/config的组权限设置,而不是 它是文件/文件夹的所有者值。

在这种情况下,所有者值应该是leecy,并且显示 的cygwingit bash 表示已正确设置, 但事实并非如此。我不得不运行以下 命令一次(在cygwin)以正确设置值。

chown -R $USER ~/.ssh 

在此更改之后,我的 cygwin gitgit bash 都工作了。

以下是我在修复前后看到的完整记录:

在修复之前,cygwin 说所有者是leecy

$ ls -ld ~/.ssh
drw-------+ 1 leecy EMEA+Domain Users 0 Aug  8 22:18 /home/leecy/.ssh


$ ls -ld ~/.ssh/*
-rwxr-xr-x  1 leecy EMEA+Domain Users  135 Aug 16 13:35 /home/leecy/.ssh/agent.env
-rw-------  1 leecy EMEA+Domain Users  352 Jun  6 13:33 /home/leecy/.ssh/config
-rw-------  1 leecy EMEA+Domain Users 1766 May  8 19:32 /home/leecy/.ssh/id_rsa
-rwxr-xr-x  1 leecy EMEA+Domain Users  403 Jun  6 11:58 /home/leecy/.ssh/id_rsa.pub
-rw-r--r--  1 leecy EMEA+Domain Users 1582 Jun  6 11:50 /home/leecy/.ssh/known_hosts

(这个改动可能没关系,但我在测试的时候确实做了。)

$ chmod 600 ~/.ssh/agent.env

ssh 测试失败

$ ssh -v -p 29418 leecy@gerrit.app.foo.com
OpenSSH_7.5p1, OpenSSL 1.0.2k  26 Jan 2017
Bad owner or permissions on /home/leecy/.ssh/config

然后我运行了这个命令

$ chown -R $USER ~/.ssh

从表面上看,owner的价值还是一样的

$ ls -ld ~/.ssh/*
-rw-------  1 leecy EMEA+Domain Users  135 Aug 16 13:35 /home/leecy/.ssh/agent.env
-rw-------  1 leecy EMEA+Domain Users  352 Jun  6 13:33 /home/leecy/.ssh/config
-rw-------  1 leecy EMEA+Domain Users 1766 May  8 19:32 /home/leecy/.ssh/id_rsa
-rwxr-xr-x  1 leecy EMEA+Domain Users  403 Jun  6 11:58 /home/leecy/.ssh/id_rsa.pub
-rw-r--r--  1 leecy EMEA+Domain Users 1582 Jun  6 11:50 /home/leecy/.ssh/known_hosts


$ ls -ld ~/.ssh
drw-------+ 1 leecy EMEA+Domain Users 0 Aug  8 22:18 /home/leecy/.ssh

但现在我的 ssh 工作了

$ ssh -v -p 29418 leecy@gerrit.app.foo.com
(worked)

【讨论】:

    猜你喜欢
    • 2014-06-17
    • 2013-02-11
    • 2011-03-31
    • 2010-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-26
    • 2011-12-27
    相关资源
    最近更新 更多