2

I am trying to save iptables rules file to /etc/sysconfig/iptables. I want to do this without logging in to root. I tried to using

sudo iptables-save > /etc/sysconfig/iptables

but it throws permission denied error.

How can i save the file without logging in to root ? I am using this in my app so i don't want to login to root through the app.

Thanks

2 Answers 2

6

To use sudo, you can do sudo iptables-save | sudo tee /etc/sysconfig/iptables

The shell don't have the right to write in /etc/sysconfig/iptables, as it is run in your user.

1

the standard out redirect is being issued by you not root ... this one-liner works

sudo bash -c "iptables-save > /etc/iptables/rules.v4 "

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .