SSH not landing in the home directory
Solution 1
did you use the -m
option when you used usermod -d
?
if not, then you need to actually move the home directory as well as change the entry in /etc/passwd.
This will rename /home/pi to /home/user if /home/user does not already exist:
cd /home
[ ! -e user ] && sudo mv pi user
oterwise, check that user
's home directory is actually /home/user
and not just /home
...here are some of the methods you can use to find out a user's home dir:
grep '^user:' /etc/passwd # works for system-local accounts only
finger user # requires finger to be installed
pinky -l user # part of GNU coreutils
getent passwd user # should work no matter where the account
data is stored
Solution 2
I'm having the same problem using Raspbian. After adding a user named "bill", raspbian failed to create the user's home directory. Although I had created the user account using "useradd bill && passwd bill", and although the /etc/passwd file contained the expected path to /home/bill as the home directory, the actual path "/home/bill" was never created. I had to manually create /home/bill as root, and then use chmod and chown to change the permissions and ownership to the right value. Now when I log on as "bill" using ssh, I end up in the "/" directory rather than in /home/bill. The /home/bill/.bashrc file does not do any trickery to change the directory from the default value of /home/bill.
It would appear that raspbian doesn't work the way that every other linux distribution works. This is clearly a BUG.
Related videos on Youtube
Pere Tuset
Updated on September 18, 2022Comments
-
Pere Tuset over 1 year
I have recently installed Raspbian into a Raspberry Pi. As part of the installation process I changed the user name and group from the default (
pi
) to my own (let's call ituser
) usingusermod
andgroupmod
. I also moved the home directory (/home/pi
) to the new user name (/home/user
) usingusermod
. Everything works fine except that when I login using SSH instead of landing the new user directory (/home/user
) I end up at the home directory (/home
). Any idea why this may be happening? Any solution? It's not a big deal but it is confusing me.The directory
/home/user
exists with permissions 755. In addition to that the/etc/passwd
file contains an entry that looks like the following:user:x:1000:1000:User:/home/user:/bin/bash
To me everything looks fine, but still when I login from ssh I get a prompt that looks like
user@raspberrypi /home $
.-
Admin over 11 yearsYou may have better luck with this question at the Raspberry Pi Stack Exchange.
-
Admin over 11 years@MichaelHampton Raspberry Pi tends to migrate questions purely about software to Unix & Linux, actually. I think this question would be considered off-topic on Raspberry Pi.
-
Admin over 11 yearsWhat's the content of your
~/.bash_profile
,~/.profile
,~/.bashrc
(if they exist)? If you runssh raspberrypi pwd
andssh raspberrypi 'echo ~'
, what does it show? -
Admin over 11 yearsI tried both your commands and both return
/home/user
(where user is the actual username). The contents of the other files (they do exist) is the default that comes with Raspberry Pi.
-
-
Pere Tuset over 11 yearsThe directory /home/user exists with permissions 755. In addition to that the /etc/passwd file contains an entry that looks like the following: user:x:1000:1000:User:/home/user:/bin/bash. To me everything looks fine, but still when I login from ssh I get a prompt that looks like user@raspberrypi /home $. Any further ideas?
-
Alessio over 11 yearsvery odd. have you checked your log file to see if there are any error/warning messages from sshd? try /var/log/messages, /var/log/syslog and/or /var/log/auth.log
-
Alessio over 11 yearsalso, what happens when you type
cd
and hit enter (it should take you to your home dir). -
Alessio over 11 yearsalso, i just noticed that you said the prompt says
... /home $
. did you check if that's correct? it might just be a problem with your prompt string, $PS1 . runpwd
to print the current working directory name. -
Shadur over 11 yearsAlso, what is the ownership of /home/user?
-
Kusalananda almost 3 yearsWhat's
chdir
? This reads more like a comment than an answer, or possibly like a follow-up question. -
Cuthbert Nibbles almost 3 yearsI thought
chdir
could be used to (basically) change the path of ~ which would make it a viable work-around, but I was mistaken. I'm going to delete the reply as it is effectively a comment.