Permission denied with sudo

My command does not work, plz halp

$ sudo usbguard generate-policy > /etc/usbguard/rules.conf
bash: /etc/usbguard/rules.conf: Permission denied

The command does however work in other directories like:

$ sudo usbguard generate-policy > test

I don’t want to change permissions of the file /etc/usbguard/rules.conf

This inconvenient work around does work:
$ sudo usbguard generate-policy

copy output

$ sudo nano /etc/usbguard/rules.conf

Paste output

You have to quote the output redirection in order for sudo to include it in its elevated privileges. :point_down:

sudo 'usbguard generate-policy > /etc/usbguard/rules.conf'
1 Like

When writing output of a command to a file in a protected location you may use a pipe instead

usbguard generate-policy | sudo tee /etc/usbguard/rules.conf
2 Likes

This did not work for me:

$ sudo 'usbguard generate-policy > /etc/usbguard/rules.conf'
sudo: usbguard generate-policy > /etc/usbguard/rules.conf: command not found

But this did also work for me:
sudo bash -c "usbguard generate-policy > /etc/usbguard/rules.conf"

1 Like

This topic was automatically closed 3 hours after the last reply. New replies are no longer allowed.