How To Redirect Sudo Output To A File Requiring Origin Permission

sudo is the recommended agency to execute a dominance which requires root permission. In effect, the target dominance takes on the permission of root without having to supply the root password.

Consider the next scenario. In guild to salve the changes made to the iptables firewall rules, I bespeak to live on the next dominance which outputs the changes to a file alongside root permission.

$ sudo iptables-save > /etc/iptables/rules.v4 bash: /etc/iptables/rules.v4: Permission denied

Note that sudo responded alongside the Permission denied error. The employment was that the iptables-save dominance was live on nether sudo, only the output redirection to the /etc/iptables/rules.v4 file was handled past times the vanquish in addition to thus nether the non-root user.

To overcome the problem, you lot tin privy write a unproblematic vanquish script in addition to live on the script using sudo similar this:

$ truthful cat > myscript.sh #!/bin/sh iptables-save > /etc/iptables/rules.v4 $ chmod +x myscript.sh $ sudo myscript.sh
If you lot don't desire to write a script, the next are roughly alternatives.
  • $ sudo sh -c "iptables-save > /etc/iptables/rules.v4"
  • $ echo 'iptables-save > /etc/iptables/rules.v4' | sudo bash
  • $ sudo iptables-save|sudo tee /etc/iptables/rules.v4 >/dev/null

Berlangganan update artikel terbaru via email:

0 Response to "How To Redirect Sudo Output To A File Requiring Origin Permission"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel