This is the shell command that results in "Permission denied" when I'm trying to append the data in a file to another file with sudo:
sudo cat add_file >> /etc/file
The file at /etc/file
is owned by root
(i.e. me) and its permissions are rw-r--r--
. Should I become root
for a moment to make it work or is there a workaround for sudo
?
To fix the permission denied error in Linux, one needs to change the file permission of the script. Use the “chmod” (change mode) command for this purpose.
Solution to fix the bash: ./program_name: permission denied error. chmod u+x program_name– In this line, the chmod command will change the access mode to execute, denoted by x. only the file's owner will have the permission to execute the file.
sudo is a command that give you root privilege. But sh is an interpreter. When you use sudo command , you running the command as root privilege. But when you use sudo sh command , you running the sh command as root.
Run bash
as sudo
:
$ sudo bash -c "cat add_file >> /etc/file" $ whoami;sudo bash -c "whoami";whoami iiSeymour root iiSeymour
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With