On Mon, Dec 23, 2024 at 20:48:12 -0500, Dan Purgert wrote: > On Dec 23, 2024, Timothy M Butterworth wrote: > > sudo fails with a permission denied error. > > tmb@hp-debian:~$ sudo /usr/sbin/iptables-save > /etc/iptables/rules.v4 > > bash: /etc/iptables/rules.v4: Permission denied > > "sudo" only modifies "iptables-save", and not the redirect (it happens > as your user, *before* the invocation of sudo, as I recall).
Correct. Redirects are done by the shell, not by the command the shell executes. The command inherits the redirection. > You'll need something like this, so that rules.v4 is opened as root > rather than your user: > sudo /usr/sbin/iptables-save | sudo tee /etc/iptables/rules.v4 Or: sudo sh -c '/usr/sbin/iptables-save > /etc/iptables/rules.v4'