git - git在git pull上破坏ssh的权限

标签 git magento ssh

我正在一个即将上线的Magento网站上工作,我使用下面的shell脚本set the permissions of the Magento project as recommended by Magento

#!/bin/bash
# Script to set permissions on Magento as recommeneded in the Magento Docs
# http://devdocs.magento.com/guides/m1x/install/installer-privileges_after.html
find . -type f -exec chmod 400 {} \;
find . -type d -exec chmod 500 {} \;
find var/ -type f -exec chmod 600 {} \;
find media/ -type f -exec chmod 600 {} \;
find var/ -type d -exec chmod 700 {} \;
find media/ -type d -exec chmod 700 {} \;

但是,执行此脚本后,我无法再执行git pull,但收到ssh错误,提示它无法解析主机名并检查我的访问权限。
$ sudo git pull
ssh: Could not resolve hostname our-git-repo: Name or service not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
our-git-repo是在host文件中设置的~./.ssh/config

当我将Magento项目根目录的权限递归更改为777时,可以解决此问题,因此我可以成功执行git pull
$ sudo chmod 777 -R /var/www/magento-project/
$ git pull
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 3), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
From our-git-repo:/var/git/magento-project
   175..........376  master     -> origin/master
   fa8..........d24  magento-uat -> origin/magento-uat
Updating 175e490..d6f8376
Fast-forward
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

1. 为什么Magento项目上的文件夹偏移会影响 ssh
ssh: Could not resolve hostname our-git-repo: Name or service not known

2. 我应该在shell脚本中设置哪些权限,以便git pull工作?

更新

即使在.git/目录上设置了正确的权限之后,我仍然遇到相同的问题。

我认为这与所有权有关,当我将sudo su放入根目录并运行ls -al命令以查看~./.ssh/的权限和所有权时,我看不到文件夹的完整内容。

知道为什么吗?这可能是问题的原因吗?
$ sudo chmod -R 755 .git/
$ sudo git pull
ssh: Could not resolve hostname our-git-repo: Name or service not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
$ sudo ls -al ~/.ssh/
total 36
drwx------ 2 ubuntu ubuntu 4096 Aug 28 15:03 .
drwxr-xr-x 8 ubuntu ubuntu 4096 Sep  3 08:51 ..
-rw------- 1 ubuntu ubuntu 1533 Aug 28 13:35 authorized_keys
-rw------- 1 ubuntu ubuntu  167 Aug 28 15:03 config
-r-------- 1 ubuntu ubuntu 1671 Aug 28 14:59 dev-aws.pem
-rwx------ 1 ubuntu ubuntu 1430 Aug 28 15:00 fz_key.ppk
-rw------- 1 ubuntu ubuntu 3326 Aug 28 14:07 id_rsa
-rw------- 1 ubuntu ubuntu  759 Aug 28 14:07 id_rsa.pub
-rw------- 1 ubuntu ubuntu  222 Aug 28 14:02 known_hosts
$ sudo su
# ls -al ~/.ssh/
total 12
drwx------ 2 ubuntu ubuntu 4096 Jun 18 16:45 .
drwx------ 4 root   root   4096 Sep  1 13:31 ..
-rw------- 1 ubuntu ubuntu 1097 Aug 28 13:35 authorized_keys

最佳答案

重要文件夹是项目中的.git文件夹。为您的Git用户设置对该文件夹的写权限。例如:

chmod -R 755 .git/

然后它应该工作。您不需要设置完整的文件夹。

关于git - git在git pull上破坏ssh的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32348606/

相关文章:

authentication - 在客户端第一次连接到服务器时,VPN 是否可能出现 "man in middle"?

linux - 在 git bash 中设置斜杠目录

android - 如何将现有的 android 项目推送到组织的存储库?

php - 当使用新的支付模块在 Magento 中加载购物车时,我收到一个我无法追踪的错误

cakephp - Magento 可以与 CakePHP 集成吗?

javascript - 使用 JavaScript 或 PHP 从网站启动 putty(带参数)

xcode - Github 操作 : xcodebuild fails due to server fingerprint

git - 我可以推送到 git 并强制设置最大包大小吗?

git - 企业代理 Azure Devops 与 Git

xml - 如何使用 XML Magento 覆盖 : catalog/product/view/type/default. phtml