git - -bash : hooks/post-receive: Permission denied

标签 git bash amazon-ec2

我现在正在使用 http://toroid.org/ams/git-website-howto 通过 Git 设置我的 EC2 .

我到了这一步;

 mkdir /var/www/www.example.org
 cat > hooks/post-receive
 #!/bin/sh
 GIT_WORK_TREE=/var/www/www.example.org git checkout -f
 chmod +x hooks/post-receive

但是,当我输入“cat > hooks/post-receive”或“sudo cat > hooks/post-receive”时,我收到此错误:-bash:hooks/post-receive:权限被拒绝

我已经使用我的 git 帐户设置了 SSH key ,这样就一切就绪了。我该怎么做才能做到这一点,以便我可以继续前进。在创建该工作树之前,我无法继续此步骤。

最佳答案

sudo cat > hooks/post-receive 仅以 root 用户身份运行 cat

重定向(和文件创建)以当前用户身份发生。

要在 sudo 上下文中进行重定向,您需要在 sudo shell 下将整个过程作为脚本运行。

sudo bash -c 'cat > hooks/post-receive'

关于git - -bash : hooks/post-receive: Permission denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27953845/

相关文章:

git - 推送到新的远程分支时更新被拒绝错误

git - 更改 git 提交消息并保持 SHA 不变

linux - Bash - 将 2 个 ssh 调用合并为 1 个(带有可选和强制命令)

git - 使用代码分发 git 配置

git - 为 github 创建公共(public) git 存储库的分支

linux - Bash 尝试执行 heredoc 中的命令

bash - 调整大小/裁剪和附加 4 张图像

amazon-ec2 - cloud-init:延迟 disk_setup 和 fs_setup

amazon-ec2 - 不同区域的EC2实例可以通过其私有(private)IP地址进行通信吗?

java - JDBC-Mysql Amazon EC2连接