I'm facing this problem - when I ssh to the server, the user is authenticated correctly, but then the connection is closed with:

Could not chdir to home directory /home/blazej: No such file or directory.

getent passwd blazej shows:



# Begin SFTP-Server block
Match Group sftp
    ChrootDirectory %h
    AllowTCPForwarding no
    X11Forwarding no
#    ForceCommand internal-sftp // This is commented not to force sfto on `sftp` group - I want to be able to ssh with users in `sftp` group
    PasswordAuthentication yes
# End SFTP-Server block

luqo33 user belongs to groups: blazej, sftp

I do not see why ssh'ing with blazej user would fail. On the other habd, sftp works as expected and logs the user to his home dir /home/blazej.

Do you have any idea why I ssh'ing in the terminal fails?

Further details:

ls -la in /home/blazej :

root@host:/home/blazej# ls -la

total 32
drwxr-x--- 5 root   sftp     4096 Nov 21 09:00 .
drwxr-xr-x 5 root   root     4096 Nov 21 09:00 ..
-rw-r--r-- 1 blazej blazej    220 Apr  8  2014 .bash_logout
-rw-r--r-- 1 blazej blazej   3637 Apr  8  2014 .bashrc
drwxr-x--- 2 blazej www-data 4096 Nov 21 09:00 exports
drwxr-x--- 2 blazej www-data 4096 Nov 21 09:00 imports
drwxr-x--- 2 blazej www-data 4096 Nov 21 09:00 other
-rw-r--r-- 1 blazej blazej    675 Apr  8  2014 .profile
  • ls -la /home/blazej please – Rui F Ribeiro Nov 21 '15 at 15:05
  • @RuiFRibeiro, I've updated my question – luqo33 Nov 21 '15 at 15:13
  • The user blazej does not own the directory, it does not look right. – Rui F Ribeiro Nov 21 '15 at 15:23
  • I'd be more worried about the lack of a shell in the getent output. – thrig Nov 21 '15 at 15:46
  • @RuiFRibeiro which directory doesn't the user blazej own? – luqo33 Nov 21 '15 at 15:54

I do not see why ssh'ing with blazej user would fail.

The user is chroot-ed to his home directory (%h is his home directory). This means that consequent cd will fail, since the root is for the process /home/blazej and there is no /home/blazej/home/blazej.

  • This seems a bit strange. What's the way out then? – luqo33 Nov 21 '15 at 15:58
  • @luqo33 You can try to pass -d / to sftp-server in your sshd_config. It may help. – Jakuje Nov 21 '15 at 16:03
  • @Jakuje I do not really see how the system would try to chroot to /home/blazej/home/blazej. A user's home dir is an an absolute path home/blazej. %h would also be am absolute directory. It'd not matter where cd would be executed. – luqo33 Nov 21 '15 at 16:41
  • 1
    Have a look on the manual page for chroot to understand this part. It is crucial. Chroot changes root, as advised by name. So after that, user will see absolute directory /home/blazej as / and than the chdir will try to change to /home/blazej again, but from the new root, which will effectively end in the described path. – Jakuje Nov 21 '15 at 16:45

I had the same problem right know. In order to fix this I set

ChrootDirectory /home/%u

and changed the user's home directory with

usermod -d / <user>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.