Ubuntu – Folder permissions changed automatically

12.10directorypermissions

Hey guys first of all I searched a lot on this site but didnt get any exact answer to my questions.
Dont know something happened automatically and all the folders permissions changed automatically and there came a lock icon on all of my folders and files.
Then I searched on this site and got the solution as this command

sudo chown 777 -R $USER:$USER $HOME

It solved my problem half way, it removed the lock icon but now all folders permissions are read only so please guide me how to reset all the folder permissions as it was previously?

I'm using ubuntu 12.10

Thanks

Best Answer

DONT DO THIS!

You have written that you have done sudo chown 777 -R ${USER}:${USER} ${HOME}

1. Problem

Your are using sudo to do an operation which should normally change resources you're controlling with your current user. This is extremely unsafe.

2. Problem

You are using sudo and environment variables. This may lead you in to an error situation. For illustration try the following.

  • sudo echo $USER --> e.g. shivam
  • sudo echo '$USER' --> root

3. Problem

chown will change the ownership of a file. Luckily you have add a failure. The parameter 777 would be identified as user name that is not existing and the file ${USER}:${USER} is not found.

The command chmod is responsible for changing file or directory permissions.

Fixing the permissions of all folders below a distinct directory.

Use the following to change the folder permissions below a distinct directory:

find BASEDIR -type d -exec chmod u+rwx \{\} \;

In your case replace BASEDIR with ~. For the bash ~ will be replaced with the home directory of the current user.

This will process only directories (not files) and set the read, write and enter (aka execute) permissions for the owner of the directory.

For more informations please read man chmod

Notes:

  • Be careful with the recursive option -R because it will process all directories and files below the given directory.
  • Use the symbolic permission notation like u+rwx, because it is easier to understand.
  • Don't use sudo if you`re not realy need it.

Check that your filesystem is mounted correctly

Ensure that the partition containing the problematic home directory is mounted read-write.

  grep /home /proc/mounts  

This should give an similar output:

/dev/mapper/system-home /home ext4 rw,relatime,discard,commit=600,data=ordered 0 0

If the rw option is not shown, then the partition is mounted for some reasons (e.g. inconsistency) read only. If this is the case invoke a file system check. This is normally also invoked during the boot of your computer.

Related Question