# Error: can't cd to /home as new user



## ban25 (Jul 24, 2011)

Hi,

I'm setting up a new FreeBSD 8.2 system and I'm having trouble creating new users.  I've added a new user via adduser:


```
Username: perforce
Full name: Perforce User
Uid (Leave empty for default): 
Login group [perforce]: 
Login group is perforce. Invite perforce into other groups? []: 
Login class [default]: 
Shell (sh csh tcsh bash rbash nologin) [sh]: 
Home directory [/home/perforce]: 
Home directory permissions (Leave empty for default): 
Use password-based authentication? [yes]: no
Lock out the account after creation? [no]: 
Username   : perforce
Password   : <disabled>
Full Name  : Perforce User
Uid        : 1001
Class      : 
Groups     : perforce 
Home       : /home/perforce
Home Mode  : 
Shell      : /bin/sh
Locked     : no
OK? (yes/no): yes
adduser: INFO: Successfully added (perforce) to the user database.
```

But when I su to this user, I can't change to the home directory:


```
# su perforce
$ ls
$ cd
cd: can't cd to /home/perforce
```

Any thoughts as to what's wrong here?


----------



## DutchDaemon (Jul 24, 2011)

Check the output of

[cmd=]ls -ld /home[/cmd]
[cmd=]ls -ld /home/perforce[/cmd]
[cmd=]ls -ld /usr/home/perforce[/cmd]


----------



## _martin (Jul 24, 2011)

Hi, 

Check if the /home/perforce actually exists and if so, check the ownership/permissions on it. Do those checks as root.


----------



## ban25 (Jul 24, 2011)

Ok, here's what I get:


```
# ls -ld /home /home/perforce /usr/home
lrwxr-xr-x  1 root      wheel       8 Jul 23 19:12 /home -> usr/home
drwxr-xr-x  2 perforce  perforce  512 Jul 24 19:47 /home/perforce
drwxr-xr-x  3 root      wheel     512 Jul 24 19:47 /usr/home
```


----------



## DutchDaemon (Jul 24, 2011)

When you *su* to the perforce user, what does *pwd* tell you? And if you *su -* to that user?


----------



## ban25 (Jul 24, 2011)

```
# su perforce
$ pwd
/root
$ cd ~
cd: can't cd to /home/perforce
$ exit
# su - perforce
su: no directory
```


----------



## _martin (Jul 24, 2011)

It seems like su can't read the directory. Are you using NFS (automount) or similar for home? Also check 

`# ls -ld /`


----------



## DutchDaemon (Jul 24, 2011)

What does the perforce user look like in /etc/master.passwd, and what is in /home/perforce itself?


----------



## ban25 (Jul 25, 2011)

Here you go:


```
# ls -ld /
drwxr-xr-x  18 root  wheel  512 Jul 23 19:12 /
# ls -la /home/perforce/
total 20
drwxr-xr-x  2 perforce  perforce  512 Jul 24 19:47 .
drwxr-xr-x  3 root      wheel     512 Jul 24 19:47 ..
-rw-r--r--  1 perforce  perforce  763 Jul 24 19:47 .cshrc
-rw-r--r--  1 perforce  perforce  261 Jul 24 19:47 .login
-rw-r--r--  1 perforce  perforce  171 Jul 24 19:47 .login_conf
-rw-------  1 perforce  perforce  383 Jul 24 19:47 .mail_aliases
-rw-r--r--  1 perforce  perforce  343 Jul 24 19:47 .mailrc
-rw-r--r--  1 perforce  perforce  789 Jul 24 19:47 .profile
-rw-------  1 perforce  perforce  288 Jul 24 19:47 .rhosts
-rw-r--r--  1 perforce  perforce  984 Jul 24 19:47 .shrc
# cat /etc/master.passwd | grep perforce
perforce:*:1001:1001::0:0:Perforce User:/home/perforce:/bin/sh
# df
Filesystem 1K-blocks   Used   Avail Capacity  Mounted on
/dev/da1s1   5071316 452456 4213156    10%    /
devfs              1      1       0   100%    /dev
/dev/da0     1040280  21424  966428     2%    /boot/grub
```

This is on an Amazon EC2 instance.  Not sure if that helps any.


----------



## DutchDaemon (Jul 25, 2011)

Well, that's odd. All I can suggest now is to run a [cmd=]truss su - perforce[/cmd] and comb through the system calls. Post output to pastie.org / pastebin.com.


----------



## ban25 (Jul 25, 2011)

Thanks, here it is:

http://pastebin.com/rCZH9ekx


----------



## DutchDaemon (Jul 25, 2011)

Well, nothing out of the ordinary there. Some things to look for or try:

Is user perforce listed in /etc/passwd with the correct home directory as well? Run `cd /etc/ && pwd_mkdb -p /etc/master.passwd` to make sure and try again.

Remove the user perforce with *rmuser* and create again. Try again.

Move /home/perforce aside and re-create the directory containing nothing (no skel files, nothing). Set  proper permissions with *chmod* and *chown*. Try again.


----------



## ban25 (Jul 25, 2011)

Didn't work.  I've noticed that the perforce user can't run many commands or cd anywhere...except *some* locations:


```
ip-10-170-13-115# pwd
/root
ip-10-170-13-115# su perforce
$ cd  
cd: can't cd to /home/perforce
$ cd /
$ cd /home
cd: can't cd to /home
$ cd /usr
cd: can't cd to /usr
$ cd /var
$ ls   
account		cron		lib		preserve	yp
at		db		log		run
audit		empty		mail		rwho
backups		games		msgs		spool
crash		heimdal		named		tmp
$ clear
clear: Permission denied
```

Somehow, I can cd to /var, but not /usr or /home....check this out:


```
drw-r-----  14 root  wheel      512 Jul 24 19:47 usr
drwxr-xr-x  23 root  wheel      512 Jul 23 18:41 var
```

Permissions on /usr were wrong, and /home is symlinked from /usr/home!

Works fine now!  Thanks


----------



## DutchDaemon (Jul 25, 2011)

Ah yes, that was the one thing we didn't get to yet ... that's a weird directory mode to have. Oh well.


----------

