首页 > 系统服务 > 详细

Ubuntu16.04 使用sudo cat EOF 编辑文件,提示Permission denied错误的解决办法

时间:2018-12-19 23:19:25      阅读:374      评论:0      收藏:0      [点我收藏+]

 

一、执行命令报错
在Ubuntu16.04下,使用如下命令,修改hosts主机文件,居然提示权限错误:

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:~$

二、解决办法1

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:~$

三、解决办法2:

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:~$

 

参考链接:
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

Ubuntu16.04 使用sudo cat EOF 编辑文件,提示Permission denied错误的解决办法

原文:https://www.cnblogs.com/rancher-maomao/p/10146860.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!