一、执行命令报错
在Ubuntu16.04下,使用如下命令,修改hosts主机文件,居然提示权限错误:
[email protected]:~$ sudo cat <<EOF > /etc/hosts
127.0.0.1 localhost
192.168.1.101 master1
192.168.1.102 worker1
192.168.1.103 worker2
192.168.1.104 worker3
EOF
-bash: /etc/hosts: Permission denied
[email protected]:~$
二、解决办法1
[email protected]:~$ sudo bash -c "cat > /etc/hosts" <<EOF
127.0.0.1 localhost
192.168.1.101 master1
192.168.1.102 worker1
192.168.1.103 worker2
192.168.1.104 worker3
EOF
[email protected]:~$
三、解决办法2:
[email protected]:~$ sudo tee /etc/hosts >/dev/null <<EOF
127.0.0.1 localhost
192.168.1.101 master1
192.168.1.102 worker1
192.168.1.103 worker2
192.168.1.104 worker3
EOF
[email protected]:~$
参考链接:
https://superuser.com/questions/340074/bash-permission-denied-issue-when-trying-to-append-to-eof
https://www.iteye.com/topic/1127130
http://www.ebanban.com/?p=677
原文地址:https://www.cnblogs.com/rancher-maomao/p/10146860.html