1、執行命令報錯
在Ubuntu16.04下,使用以下命令,修改hosts主機文件,竟然提示權限錯誤:node
catty@node186:~$ 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
catty@node186:~$ bash
2、解決辦法1app
catty@node186:~$ 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
catty@node186:~$ spa
3、解決辦法2:it
catty@node186:~$ 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
catty@node186:~$ io
參考連接:
https://superuser.com/questions/340074/bash-permission-denied-issue-when-trying-to-append-to-eofast
https://www.iteye.com/topic/1127130權限
http://www.ebanban.com/?p=677hosts