Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 560
Desmond Hume Avatar asked Dec 08 '12 15:12

Desmond Hume


People also ask

How do I fix permissions denied in Linux?

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.

How do I fix bash Permission denied in Linux?

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.

What is sudo sh?

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.


1 Answers

Run bash as sudo:

$ sudo bash -c "cat add_file >> /etc/file"  $ whoami;sudo bash -c "whoami";whoami iiSeymour root iiSeymour 
like image 92
Chris Seymour Avatar answered Sep 21 '22 22:09

Chris Seymour