0

I added a user tomcat in the sudoers file like this :

tomcat ALL=(ALL)        NOPASSWD:ALL

Then I noticed a problem. When I type :

sudo vim /etc/hosts

I can make my changes without any problem. But when I try this I get an error:

sudo echo "address host" >> /etc/hosts
-bash: /etc/hosts: Permission denied

Can someone explain to me why?

fedorqui
  • 252,262
  • 96
  • 511
  • 570
Jachk E
  • 420
  • 1
  • 5
  • 11
  • From the duplicate question: _The problem is that the shell does output redirection, not sudo or echo, so this is being done as your regular user._ – fedorqui May 03 '16 at 08:48

1 Answers1

0

This fails because current shell is doing the redirection not "echo". Since current user doesn't have permission to write to the file "/etc/hosts" hence " permission denied error". Do this way:

echo "address host" | sudo tee -a /etc/hosts
jijinp
  • 2,543
  • 1
  • 12
  • 15