Folder permissions changed automatically

8,759

Solution 1

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.

Solution 2

The biggest problem is that all of your files are in a state that, however readable now, they are pretty unusable.

The problem with setting permissions by hand is that not all files have the same permission set (think about your ssh-keys for instance, you don't want somebody else be able to read them) so you are in a messy situation where you have to decide for every single file which permissions they should have.

The best thing you can do is create a new account and copy the files you need from the old account. Permissions will then be set automatically. Also if you need your personal settings you can copy them also from your old account. They are in hidden files or hidden directories in your home directory. Be careful to only copy what you need.

Also it might be wise to do a filesystemcheck afterwards.

Share:
8,759

Related videos on Youtube

shivamDev31
Author by

shivamDev31

A passionate Android Developer. Developer helping other developers. Hangouts and Gmail id : [email protected]

Updated on September 18, 2022

Comments

  • shivamDev31
    shivamDev31 over 1 year

    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

    • shivamDev31
      shivamDev31 about 11 years
      But as its read only now, Im not able to do anything...I think it changed the owner or something...please help me out guys...
  • shivamDev31
    shivamDev31 about 11 years
    can you guide me with BASEDIR ?? ..Im new to linux
  • shivamDev31
    shivamDev31 about 11 years
    These are the results : shivamd@shivam:~$ grep /home /proc/mounts shivamd@shivam:~$ /dev/mapper/system-home /home ext4 rw,relatime,discard,commit=600,data=ordered 0 0 bash: /dev/mapper/system-home: No such file or directory shivamd@shivam:~$
  • shivamDev31
    shivamDev31 about 11 years
    I think first time I tried this command without 777 sudo chown 777 -R ${USER}:${USER} ${HOME} like sudo chown -R ${USER}:${USER} ${HOME}
  • shivamDev31
    shivamDev31 about 11 years
    Nopes actually I used that tool and replaced it with my home directory name...But it gave me error as directory not found I ran this command : find shivamd -type d -exec chmod u+rwx \{\} \;
  • H.-Dirk Schmitt
    H.-Dirk Schmitt about 11 years
    sudo chown -R ${USER}:${USER} ${HOME} not good, but likely it hasn't scramled anything because normally $USER:USER is the right ownership for user and group of any item below the user home directory.
  • H.-Dirk Schmitt
    H.-Dirk Schmitt about 11 years
    For the BASEDIR see again the updated answer.
  • H.-Dirk Schmitt
    H.-Dirk Schmitt about 11 years
    Provide a new question with detailed informations ;-)