繁体   English   中英

Git 可以覆盖 root 拥有的文件(无 sudo)

[英]Git can overwrites files owned by root (no sudo)

我有一个 Git 文件夹,其中包含我拥有的文件(“francois”)和“root”拥有的文件。

记录一下:root 拥有的文件链接到/etc/network/if-up.d以在启动时激活网络时由 root 执行。 因此,如果我让标准用户访问这些内容,那将是危险的。

当我git commit这些文件时,正如预期的那样,我做了sudo git commit 但是git pullgit checkout可以控制这些文件甚至更改所有者。

这是git checkout的示例:

francois@computer:~/appli_bash$ sudo chown root app_times_update.sh

francois@computer:~/appli_bash$ sudo chmod 700 app_times_update.sh

francois@computer:~/appli_bash$ ll
blabla…
-rwx------  1 root       dreamtroic 5988 févr.  3 18:43 app_times_update.sh*
blabla…

francois@computer:~/appli_bash$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   app_times_update.sh

no changes added to commit (use "git add" and/or "git commit -a")

francois@computer:~/appli_bash$ git checkout app_times_update.sh

francois@computer:~/appli_bash$ ll
blabla…
-rwxrwxr-x  1 francois francois 5988 févr.  3 18:44 app_times_update.sh*
blabla…

当我git pull时,我也做了类似的观察。

我发现 Git 实际上没有“看到” chown ,只有chmod ......但这并不能真正解释 Git 如何克服根所有权。 不是安全问题吗?

此外,如果您对更好地组织我的工作有任何建议(这种经验表明我应该这样做),我很乐意阅读。

谢谢!

git checkout只对现有文件做一件事:它删除它,它只需要当前目录的写权限。

删除文件后,Git 将创建一个由当前用户及其默认组拥有的新文件,如果跟踪的文件是可执行的,则具有 755 权限,否则为 644。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM