Issue
I am trying to giving permission to root user generated file but not able to do this. Can anyone help me how to do this?
I tried:
echo -e 'password'> sudo chmod 777 file.txt
Example:
file.txt rw-r--r-- root
Expected result:
file.txt rwxrwxrwx spate233
Solution
First of all, I can't see what you're doing by "echo -e 'password'". The '>' character means "output redirection", that is, bash will redirect the input of the "echo -e password" command to a file named "sudo" in the directory that you're working. The part "777 file.txt" will be appended to that file(i didn't know this, I just tested it in my PC and that's what happened).
Apart from that: if you want to access a root generated file you have to take into account that root generated files have "root" as owner and "root" as owner group.
If the user that you're trying to give permissions is a sudoer, then you can just operate using "sudo", just like you did in the example.
If it is not, and you want your user to have permissions, it would be enough to set permissions for "other" domain. You can try this:
sudo chmod o+rwx file.txt
This adds all permissions (i.e. rwx) to the other users domain.
However, if you want to give 777 permissions to the file, you just use
sudo chmod 777 file.txt
or also, if you want to use a syntax like the previous one
sudo chmod a+rwx file.txt
If it your desire, then you can also change the owner of the file. Doing this can lead to some security problems, so it is avoided if the file you are dealing with is a system file. I think this is not the case, so you can just do:
sudo chown user:group file
Where user and group are substituted with the new owner and the new group of that file.
Answered By - ArrayIndexOutOfBounds Answer Checked By - Cary Denson (WPSolving Admin)