Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question
    
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... –  Shivam Chopra Mar 4 '13 at 10:21
add comment

2 Answers 2

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.

share|improve this answer
    
can you guide me with BASEDIR ?? ..Im new to linux –  Shivam Chopra Mar 4 '13 at 10:31
    
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:~$ –  Shivam Chopra Mar 4 '13 at 10:38
    
I think first time I tried this command without 777 sudo chown 777 -R ${USER}:${USER} ${HOME} like sudo chown -R ${USER}:${USER} ${HOME} –  Shivam Chopra Mar 4 '13 at 10:39
    
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 \{\} \; –  Shivam Chopra Mar 4 '13 at 10:44
    
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 Mar 4 '13 at 10:47
show 3 more comments

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|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.