Ubuntu – chmod not working in a non super user

14.04chmodchownfiles

I have created a file named *.txt in /home using following command:

sudo nano *.txt

Then I have changed owner of *.txt to a user that I've created:

sudo useradd -c "ABC"

sudo chown ABC *.txt

I login to ABC by typing:

sudo login ABC

I tried to change permission of the file:

sudo chmod 777 *.txt

This is the result:

ABC is not in the sudoers file. This incident will be reported.

Permissions have successfully changed when running chmod from the original user: batman.

How can I change the permissions of *.txt from the new owner?

This is inside <code>ABC</code> user

Best Answer

If you step through your commands and the output these are your problems.

The file *.txt is located in batman's home directory.

  1. Switch to ABC user: sudo login ABC. You just made ABC and it doesn't have a home directory so you got thrown into the root directory

  2. You try chmod 777 *.txt, but you are in the root dir and the file is not there.

  3. You exit back into batman and try to chmod the file, but now it belongs to ABC and batman can't change it.

To Solve:

login as batman

su ABC

cd /home/batman

chown 777 *.txt
Related Question