Permission denied when trying to append a file to a root owned file with sudo [closed] Permission denied when trying to append a file to a root owned file with sudo [closed] bash bash

Permission denied when trying to append a file to a root owned file with sudo [closed]


Run bash as sudo:

$ sudo bash -c "cat add_file >> /etc/file"$ whoami;sudo bash -c "whoami";whoamiiiSeymourrootiiSeymour


Try doing this instead :

sudo tee -a /etc/file < add_file

It's lighter than running bash or sh -c command


A funny possibility is to use ed (the standard editor):

sudo ed -s /etc/file <<< $'r add_file\nwq'

I know I won't get upvoted for this wonderful answer, but I wanted to include it here anyway (because it's funny). Done!