LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 01-06-2010, 01:44 PM   #1
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 12.04 / CentOS 6.5
Posts: 387

Rep: Reputation: 61
'Could not chdir to home directory /home/[user]: Permission denied'


I have a secondary disk which holds a /home directory structure from a previous install of Linux. I installed a new version on a new primary drive and mounted this secondary drive as the new /home. Problem is, even though the users are the same names and I can access the home directories for the users, I cannot login directly to their home directories, as I get the following error: -

Code:
login as: [me]
[me]@[machine]'s password:
Last login: Wed Jan  6 18:34:33 2010 from [machine]
Could not chdir to home directory /home/[me]: Permission denied
[[me]@[machine] /]$
Now, since the usernames are correct and the users are in the passwd file with the correct home directory paths, could it be user ID's that are different or something else? It's not as though I cannot access the home directories for the users, simply that I cannot log directly into them from a login prompt.

What have I broken?

Last edited by arashi256; 01-06-2010 at 05:59 PM.
 
Old 01-06-2010, 01:50 PM   #2
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 547

Rep: Reputation: 115Reputation: 115
Have you tried using chown as root to change the ownership?
What are the permissions set as? Post the output from
Code:
ls -la /home/
 
Old 01-06-2010, 02:07 PM   #3
cardy
Member
 
Registered: Jan 2005
Location: Shropshire, England, UK
Distribution: RedHat, Fedora, CentOS..........
Posts: 121

Rep: Reputation: 19
The problem is most likely related to the user and group IDs. When you create a user it is given a userid and a primary group ID. This information is stored in /etc/password normally (unless you use some form of network based authentication).

If you look at /etc/passwd you will see a number of user entries, below is a sample for some of the passwd file users on my system
Quote:
cat /etc/passwd

root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
The file is colon separated and the fields your interested in are the 3rd and the 4th. The 3rd field is the numeric user id for the user on this system and the 4th is the primary group ID for the user. You will probably find that when you look at the output from the command provided by Devnull10 that there are user ID's shown rather than usernames.

I am guessing the previous system on which the /home directories were originally created had assigned different user id's in the password file.

As devnull10 recommends the chown command can be used to change the owner and is probably a simpler way of fixing the access than trying to change the user ids in the /etc/passwd file because other files on the linux system will be using the new user id.
 
Old 01-06-2010, 02:43 PM   #4
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 12.04 / CentOS 6.5
Posts: 387

Original Poster
Rep: Reputation: 61
The output: -

Code:
[jon@joshua11 /]$ ls -la /home/
total 24
drwxr-xr-x.  5 root   root   4096 2009-07-13 10:03 .
dr-xr-xr-x. 25 root   root   4096 2010-01-05 16:37 ..
drwx------. 32 jon    jon    4096 2010-01-06 16:14 jon
drwx------.  2 root   root   4096 2010-01-05 16:39 lost+found
[jon@joshua11 /]$
The UID and GID in the /etc/passwd file is 500 for both. How can I find out what the UID and GID for the /home/jon directory is (as I assume this is the problem)? I have already done: -

chown -R 500:500 /home/jon

...but this doesn't seem to change the login problem, although I *do* have ownership of the files and directories as this user. Am I somehow missing changing the UID and GID for the hidden files even though the username is the same? Something that used the previous UID and GID in whatever scripts automatically moves your location to your home directory when you login?

Thanks for your patience.

Last edited by arashi256; 01-06-2010 at 05:59 PM.
 
Old 01-06-2010, 02:52 PM   #5
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 547

Rep: Reputation: 115Reputation: 115
The syntax of chown is:

Code:
chown [user] [dir]
So you want to do

Code:
chown -R jon /home/jon/
Also, how come you have a separate group for your home directory? Seems a little strange unless you are wanting a limited set of other users to have some form of access?

Last edited by devnull10; 01-06-2010 at 02:53 PM.
 
Old 01-06-2010, 02:54 PM   #6
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 12.04 / CentOS 6.5
Posts: 387

Original Poster
Rep: Reputation: 61
I have already tried that to no effect. Login problem persists. Hidden files appear to have changed, but since both usernames are the same, it's hard to tell.
 
Old 01-06-2010, 03:02 PM   #7
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 12.04 / CentOS 6.5
Posts: 387

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by devnull10 View Post
Also, how come you have a separate group for your home directory? Seems a little strange unless you are wanting a limited set of other users to have some form of access?
That's the default setup for Fedora. Separate users and groups. Don't know why.

I've also done chgrp -R 500 /home/jon (and tried substituting "500" for "jon") to no effect. I have acces to the home directory as that user, just not able to automatically login to the home directory. It fails and I have to do "cd /home/jon" after logging in.
 
Old 01-06-2010, 03:42 PM   #8
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 547

Rep: Reputation: 115Reputation: 115
You could try creating a new home directory when logged in as root for the user jon. The following command will modify the user to have the home directory /home/jon_home (it will be created if it doesn't already exist). The -m flag will copy the contents of your existing home into the new directory.

Code:
usermod -d /home/jon_home -m
 
Old 01-06-2010, 04:16 PM   #9
cardy
Member
 
Registered: Jan 2005
Location: Shropshire, England, UK
Distribution: RedHat, Fedora, CentOS..........
Posts: 121

Rep: Reputation: 19
The following command will show what user/group id's are set on the directory

ls -ln /home

Is the version of linux the same as the one you had previously installed. When you create a user a default set of files are copied into the users home directory from the directory /etc/skel

It could be that your .bash_profile .cshrc or other login files are what is causing the directory failure.

It would be worth looking at these files to see if they are causing issues.

The other thing that occurs is can you run the command

cat /etc/fstab | grep /home

This will list the entry for the /home partition showing the mount options that have been used to mount it.

Regards

Lee
 
Old 01-06-2010, 05:09 PM   #10
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 12.04 / CentOS 6.5
Posts: 387

Original Poster
Rep: Reputation: 61
Thanks Cardy - that shows a little more information on /home: -

Code:
drwx------. 32 500 500 4096 2010-01-06 19:52 jon
..but the numbers are 500 as they should be as listed in /etc/passwd: -

Code:
jon:x:500:500:Jonathan:/home/jon:/bin/bash
Running "cat /etc/fstab | grep /home" yields this, which is as it should be, I suppose: -

Code:
/dev/sdb1      /home      ext3    defaults        2 1
The /home directory drive was 32-bit Fedora 11, the new system is 64-bit Fedora 12 in basically a new system. I just mounted the old drive and created users with the same names. Works fine as long as you don't mind manually cd'ing to your user home directory.

I couldn't see anything amiss with .bashrc or .bash_profile or anything like that, but it is definitely something to do with login.

Last edited by arashi256; 01-06-2010 at 06:00 PM.
 
Old 01-06-2010, 05:28 PM   #11
cardy
Member
 
Registered: Jan 2005
Location: Shropshire, England, UK
Distribution: RedHat, Fedora, CentOS..........
Posts: 121

Rep: Reputation: 19
Have you checked the following:

The output of the command

Quote:
dmesg
The log files in /var/log

Check the following files.

Quote:
messages
secure
These may give you some indication as to why your getting the errors.

Regards

Lee
 
Old 01-06-2010, 05:57 PM   #12
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 12.04 / CentOS 6.5
Posts: 387

Original Poster
Rep: Reputation: 61
Output of secure log: -

Code:
Jan  6 22:53:44 joshua11 sshd[6194]: Accepted password for jon from [IP ADDRESS] port 2143 ssh2
Jan  6 22:53:44 joshua11 sshd[6194]: pam_unix(sshd:session): session opened for user jon by (uid=0)
Jan  6 22:53:51 joshua11 su: pam_unix(su-l:session): session opened for user root by jon(uid=500)
UID = 500, which is correct. Nothing in the messages log for the time it happened, nor in dmesg.

Last edited by arashi256; 01-06-2010 at 05:59 PM.
 
Old 01-06-2010, 08:45 PM   #13
ongte
Member
 
Registered: Jun 2009
Location: Penang, Malaysia
Distribution: Mandriva, CentOS, Ubuntu
Posts: 456

Rep: Reputation: 69
Very odd looking problem you have there. Could it be a SELinux context issue?
Try looking at the output of these:
# ls --context /home
# ls --context /home/jon

If not SELinux, it could also be an ACL issue. Try:
# getfacl /home
 
Old 01-07-2010, 05:13 AM   #14
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 12.04 / CentOS 6.5
Posts: 387

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by ongte View Post
Very odd looking problem you have there. Could it be a SELinux context issue?
Try looking at the output of these:
# ls --context /home
# ls --context /home/jon

If not SELinux, it could also be an ACL issue. Try:
# getfacl /home
Code:
[root@joshua11 ~]# ls --context /home
drwx------. jon    jon    system_u:object_r:file_t:s0      jon
drwx------. root   root   system_u:object_r:file_t:s0      lost+found
[root@joshua11 ~]# ls --context /home/jon
drwxrwxr-x. jon jon unconfined_u:object_r:user_home_t:s0 Backup
drwxr-xr-x. jon jon unconfined_u:object_r:user_home_t:s0 Desktop
drwxrwxr-x. jon jon unconfined_u:object_r:user_home_t:s0 Documents
drwxrwxr-x. jon jon unconfined_u:object_r:user_home_t:s0 Downloads
drwxr-xr-x. jon jon unconfined_u:object_r:user_home_t:s0 Music
drwxr-xr-x. jon jon unconfined_u:object_r:user_home_t:s0 Pictures
drwxrwxr-x. jon jon unconfined_u:object_r:file_t:s0  Platforms
drwxrwxr-x. jon jon unconfined_u:object_r:user_home_t:s0 Programs
drwxr-xr-x. jon jon unconfined_u:object_r:user_home_t:s0 Public
drwxr-xr-x. jon jon unconfined_u:object_r:user_home_t:s0 RHCT
drwxrwxr-x. jon jon unconfined_u:object_r:user_home_t:s0 SCJP
drwxr-xr-x. jon jon unconfined_u:object_r:user_home_t:s0 Templates
drwxrwxr-x. jon jon unconfined_u:object_r:file_t:s0  Torrent-Files
drwxr-xr-x. jon jon unconfined_u:object_r:user_home_t:s0 Videos
Ah, this seems to show something different - the two directories I've added since I've run this drive (Platforms and Torrent-Files) from this new machine have different entries to the directories that were still there before - what does this mean?
 
Old 01-07-2010, 05:32 AM   #15
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Rep: Reputation: 146Reputation: 146
Could it be the change from x86 to x86_64? Maybe some architecture incompatibility?
 
  


Reply

Tags
context, directory, home, selinux


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
ssh could not chdir to home directory pccdrussell Linux - General 27 08-24-2012 11:30 AM
NFS problem: "Could not chdir to home directory /home/USER: Permission denied" sumanc Linux - Server 4 07-22-2010 05:12 PM
Crontab permission denied while making a directory in user's home Dfangs Linux - Server 3 05-29-2009 10:44 AM
How can I set the permission on the home directory when creating an user crisostomo_enrico Solaris / OpenSolaris 4 09-26-2007 07:24 PM
permission denied to home directory ekdya Debian 3 11-08-2005 05:24 PM


All times are GMT -5. The time now is 03:00 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration