【问题标题】:How i can fix zsh: permission denied: /etc/hosts?我如何修复 zsh: permission denied: /etc/hosts?
【发布时间】:2022-12-24 04:33:30
【问题描述】:

我尝试使用代码配置虚拟主机:

 echo 127.0.0.1 laravel-app.test >> /etc/hosts  

但我有一个问题“zsh:权限被拒绝:/etc/hosts”

你能帮我解决我的问题吗?

【问题讨论】:

  • 试试sudo echo 127.0.0.1 laravel-app.test >> /etc/hosts
  • 我已经这样做了,但是 zsh: permission denied: /etc/hosts

标签: laravel


【解决方案1】:

对于您的特定用途:

sudo sh -c "echo '127.0.0.1 laravel-app.test' > /etc/hosts"

这也适用于更复杂的 heredoc 案例:

sudo sh -c "cat << EOF >> /etc/hosts

#### added for development
127.0.0.1  laravel-app.test
127.0.0.1  oid-provider.test
####
EOF"

另见:https://serverfault.com/questions/769986/bash-etc-hosts-permission-denied

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-24
    • 2018-08-18
    • 2021-10-17
    • 1970-01-01
    • 2022-08-18
    • 2016-08-27
    • 1970-01-01
    • 2023-01-19
    相关资源
    最近更新 更多