0

If I try

pkexec echo -e '\nwl2k something\n' >> /etc/ax25/axports 

in terminal to have a user add a line to a file, I get a

bash: /etc/ax25/axports: Permission denied

How do I make it so the whole command goes to pkexec - that is, ask user for sudo to make the change?

1

1 Answer 1

0
pkexec echo -e '\nwl2k something\n' >> /etc/ax25/axports
bash: /etc/ax25/axports: Permission denied

Output redirects have the permissions of the user who invoked the shell, not the command that produced the output. See https://unix.stackexchange.com/a/6714/411962.

Instead pipe the echo output to pkexec tee -a file to append it to a file requiring elevated permissions: echo -e '\nwl2k something\n' | pkexec tee -a /etc/ax25/axports

2
  • 2
    The question seems to be using "ask user for sudo to make the change" as a shorthand to "request authentication to run the command with administrative privileges". The echo command needs no special privileges, but writing to a specific file does. So echo -e '\nwl2k something\n' | pkexec tee -a /etc/ax25/axports is what the question seems to be looking for.
    – telcoM
    Commented Jan 26, 2022 at 7:04
  • @telcoM You're correct of course. I just saw the >> redirect to a root-owned location, which of course never works, and gave the sudo tee method as the fix. I'll edit the answer. Commented Jan 26, 2022 at 18:58

You must log in to answer this question.

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