14

Somehow, I managed to chmod and chown my ~ into oblivion.

When I attempt to login through the shell, I get

bash: ~/.bashrc : Permission denied

Even after (as root) I've run

chown -hR nroach44 /home/nroach44

and

chmod -R 666 /home/nroach44

or (as nroach44)

chmod -R 644 /home/nroach44

None of these commands return errors.

Also:

ls -la /home/nroach44

Returns lots of

drw-rw-rw-  1 nroach44 nroach44 4096 --date-- ti:me foldername

Any Help?

2
  • Thanks all! Any guide to what files need what permissions in the home folder now? :)
    – NRoach44
    Jan 10, 2012 at 12:42
  • /home should be drwxrwxr-x and root:root and /home/user rw rw -- or r- depending if you want other users to read your users files. Directories and executable files with x. The same inside user directory won't be a problem if you have the group = user (nroach44:nroach44) like you seems to have (I would only give 0 (---) permissions on others).
    – laurent
    Jan 10, 2012 at 23:43

5 Answers 5

15

WARNING

(Do not execute these two examples!)

chmod -R 666 /home/nroach44
chmod -R 644 /home/nroach44

This will make all the files on your home dir non executable. It was not a good idea ;)

I don't know how to clean this mess, as a quick workaround you can try to do as root:

chmod -R 755 /home/nroach44

This command will give execute permissions to all files on your home folder. It should solve your immediate problems, but it could be a security nightmare.

The best solution is to open another user account and transfer to it files and settings one by one.

1
  • 7
    I didn't know that directories needed x permissions to open. Thank you!
    – NRoach44
    Jan 10, 2012 at 12:39
5

Directories need to have the execute bit set to allow you to descend into the directory. Plain 666 is just wrong, even if you're running as root. It gives everyone write permissions.

To make the files more secure, run:

chmod -R 640 /home/nroach44

To make the folders descendable again, run:

find /home/nroach44 -type d -exec chmod 750 \;

Note: I chose for xx0 because some files may be sensitive and not be read by others. Just to be save, remove the read/write/execute permissions for the world.

1
  • I was only 666'ing to test if it would work or not :)
    – NRoach44
    Jan 10, 2012 at 12:37
4

As you appear to have sufficient permissions on ~, you need /home to have x permission for others (sudo chmod +rx /home) and check if the permissions are ok on /home/nroach44/.bashrc file.

Another point, directories should have x permissions to allow entering in them so to fix them all, you need to run sudo chmod -R +X /home/nroach44.

3
  • Knowing execute permissions were needed for entering folders wouldhave been nice to know before, so thanks!
    – NRoach44
    Jan 10, 2012 at 12:40
  • I didn't know of capital X +1
    – Lekensteyn
    Jan 10, 2012 at 14:24
  • capital X is very useful and I was very happy to discover it too... after a long time using find!!
    – laurent
    Jan 10, 2012 at 23:28
1

This is because you have messed up the permissions of all files in your HOME folder. Please be very careful while playing with file permissions, use chmod and chown very carefully or you can end up with a mess.

bash: ~/.bashrc : Permission denied

I think you changed the permissions of all files in your home directory, so the permission of bashrc also got changed.

The default permissions of ~/.bashrc script is

-rw-r--r-- 1 user1 user1  3353 2012-01-09 12:05 .bashrc

To explain it, you should have both read and write permissions on the file, other users of the usergroup should be able to read it, and all others can also read it.

So now change the permissions of bashrc script using chmod to 644

chmod 644 ~/.bashrc

if the above commands gives permission denied. then

run chown first as sudo

sudo chown user1:usergrp ~/.bashrc

replace user1 with your username and usergrp with your default user group.

Now again do

chmod 644 ~/.bashrc

now you will be having permissions for basrc script, now try to login and check if you get any other errors :)

0

Directories need x bit set (for directory that bit is seen as search bit) to open. So I use tree so I can get only the folder set and avoid the nightmare of having all the files set as executables ( the option for tree is -d List directories only.):

sudo tree -faid /home/nroach44 | xargs -L1 -I{} sudo chmod 755  "{}"

Warning!!! you should have this into considerations:

  • using chmod or chown recursive on root / directory or system directories will destroy your OS (actually anything recursive on / directory or system directories is dangerous)

  • this is not a good security practice to set permission bulk like that

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .