0

I have a script file on a debian server machine that uses /sbin/iptables to ban ips that are trying to enter to my system. I had the script as a crontab entry but I've realised that it wasn't working as expected because it needed to be a root user.

Whenever I run the script as sudo myscript the the script works as expected. If I don't use sudo it gives me:

iptables v1.4.21: can't initialize iptables table `filter': Permission denied (you must be root)
Perhaps iptables or your kernel needs to be upgraded

If I type "id" I get:

uid=1000(username) gid=33(www-data) groups=33(www-data),0(root),27(sudo),1001(developers)

and groups

www-data sudo developers

So it seems that the user is inside the sudo group, however it doesn't have access to the iptables command, i.e. if I type as "username" iptalbes it tells me command not found.

Furthermore, I was reading about the /etc/sudoers that you can give access to specific users. I've changed from 440 to 740 the permission rights and I uncommented

# Allow members of group sudo to execute any command
sudo    ALL=(ALL:ALL) ALL

Now everytime I type sudo whatever command I get

username is not in the sudoers file.  This incident will be reported.

Some help would be appreciated..

Thanks

  • A group is normally defined with a % prefix in the sudoers file and so sudo should be %sudo – Raman Sailopal Jan 25 '18 at 14:45
  • Thanks Raman but how do I fix both the iptables issue and the fact that I cannot type sudo command anymore? – Symeon Mattes Jan 25 '18 at 14:50
  • By running visudo and prefixing sudo with %sudo? – Raman Sailopal Jan 25 '18 at 14:53
  • Currently I can't change anything...it always gives me : username is not in the sudoers file. This incident will be reported. – Symeon Mattes Jan 25 '18 at 14:59
  • Can you not login as root and do it? – Raman Sailopal Jan 25 '18 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.