LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-23-2016, 11:30 AM   #1
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Rep: Reputation: Disabled
Locked myself out of my home


Well, this is embarrassing. I was trying to give Apache access to a directory in my home, and did a recursive chmod and chown command on my home directory. Now I can't even access it after recursively setting everything back to 664 and as my user/group.

Questions:
  1. Why can't I access it? What do I need to do to access it?
  2. What is the best "default" permission to set things back to? 664? What about directories such as .ssh?
Code:
[Michael@devserver home]$ pwd
/home
[Michael@devserver home]$ sudo chmod 0664 -R Michael
[sudo] password for Michael:
[Michael@devserver home]$ sudo chown Michael:Michael -R /home/Michael
[Michael@devserver home]$ ls -l
total 40
drwx------.  9 git     git      4096 Apr 19  2014 git
drwx------.  2 root    root    16384 Apr 19  2014 lost+found
drw-rw-r--. 21 Michael Michael  4096 Nov 23 09:04 Michael
drwxrwxrwx.  2 root    root     4096 Dec 23  2014 mysql_log
drwx------.  4 phped   phped    4096 Apr 21  2014 phped
drwxr-xr-x.  3 root    root     4096 May 29  2014 public
drwxrwxr-x.  9 vbox    vbox     4096 May 28  2015 vbox
[Michael@devserver home]$ cd Michael
-bash: cd: Michael: Permission denied
[Michael@devserver home]$ su -
Password:
[root@devserver ~]# cd /home/Michael
[root@devserver Michael]#
 
Old 11-23-2016, 11:32 AM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Have to have the execute bit set on directories. So usually 0755 or 0775 for directories.

Last edited by szboardstretcher; 11-23-2016 at 11:35 AM.
 
2 members found this post helpful.
Old 11-23-2016, 11:36 AM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Code:
chmod -R u+X /home/Michael
The capital X means it will only add execute permissions for directories or if the file already has execute permission for some user. This is convenient for times like this where you need to add execute permissions to all directories recursively, but not the files. Keeps you from having to do a "find -type d -exec chmod" or similar.

Also if there are any executables anywhere in your home directory, you'll need to manually re-add execute permissions on each and every one of them individually.

Manually setting the octal permissions recursively for an entire directory structure is very rarely the right course of action. It usually causes far more problems than it potentially solves. Use the ugo +/- rwxX arguments to chmod instead.

Last edited by suicidaleggroll; 11-23-2016 at 11:40 AM.
 
4 members found this post helpful.
Old 11-23-2016, 11:37 AM   #4
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Original Poster
Rep: Reputation: Disabled
Thanks szboardstretcher, Well I feel silly.

To set things back to right, should I first make /home/Michael 700 recursively, then make /home/Michael 770 not recursive, and then make subdirectories either 750 or 770 on a as needed basis?

Last edited by NotionCommotion; 11-23-2016 at 11:40 AM.
 
Old 11-23-2016, 11:41 AM   #5
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Yeah. To start you can 'chmod 0775 /home/Michael'... then if you want to start to fix the Michael directory and its contents,..

As root you could chmod directories, files and scripts correctly with the commands below. You might still have some outliers to fix - like .ssh as mentioned.

Code:
find /home/Michael -type d -exec chmod 0755 {} \;
find /home/Michael -type f -exec chmod 0644 {} \;
find /home/Michael -type f -name '*.sh' -exec chmod 0774 {} \;

Last edited by szboardstretcher; 11-23-2016 at 11:42 AM.
 
1 members found this post helpful.
Old 11-23-2016, 11:41 AM   #6
notKlaatu
Senior Member
 
Registered: Sep 2010
Location: Lawrence, New Zealand
Distribution: Slackware
Posts: 1,077

Rep: Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732
Quote:
Originally Posted by NotionCommotion View Post
What about directories such as .ssh?
From `man ssh` :

Code:
     ~/.ssh/
             This directory is the default location for all user-specific configuration and authentication
             information.  There is no general requirement to keep the entire contents of this directory
             secret, but the recommended permissions are read/write/execute for the user, and not accessible
             by others.
     [...]
     ~/.ssh/id_rsa
             Contains the private key for authentication.  These files contain sensitive data and should be
             readable by the user but not accessible by others (read/write/execute).  ssh will simply ignore
             a private key file if it is accessible by others.
So

Code:
$ chmod 700 ~/.ssh 
$ chmod 400 ~/.ssh/id_rsa
 
2 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
home directory being locked soundar Red Hat 3 01-09-2011 08:36 AM
locked out of home folder scribbles Linux - Desktop 2 12-27-2010 04:29 PM
contents of 'home' directory found at sda5: mounted as /home, and also on sda6:/home leswatson Linux - Newbie 4 04-18-2008 04:02 PM
Put a 2nd kanotix at hdb 3/,-4/home. 1st is at hdb8/,-9/home.#2 is using 1st's /home sleekmason Linux - General 3 12-09-2006 09:21 AM
Newb locked out of /home/username? Charlie Spencer Linux - Newbie 7 07-21-2006 12:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration