SSH – Fix ‘/bin/bash: No Such File or Directory’ Error

chrootsshuser-management

I have a user who is jailed.

sshd_config:

Subsystem sftp internal-sftp

Match user matt
     ChrootDirectory %h
     X11Forwarding no
     AllowTcpForwarding no

passwd:

matt:x:1001:5006:Matt Ryan,,,:/home/matt:/home/matt/bin/bash

This works perfectly for sftp. The user is limited to his home folder, and whatever mounts are there.

But, I'd like to also give this use shell access. This is what happens when they attempt to log in:

$ ssh matt@server.com
Linux devnode 2.6.38-linode31 #1 SMP Mon Mar 21 21:22:33 UTC 2011 i686 GNU/Linux
Ubuntu 10.04.2 LTS

Welcome to Ubuntu!
 * Documentation:  https://help.ubuntu.com/
Last login: Thu Mar 31 13:04:29 2011 from abc.nyc.res.rr.com
/home/matt/bin/bash: No such file or directory
Connection to server.com closed.

Via fstab, the bin folder is mounted to the home directory and is present.

Why am I getting this error.. and how can I solve this?

Thanks for the help!

Best Answer

When you chroot, the named directory becomes /. The correct shell path inside the chroot is then /bin/bash, not /home/matt/bin/bash.

You will also need to make sure there's enough other stuff inside the chroot for the system to work. You can test this with sudo chroot /home/matt /bin/bash and see what works and what doesn't; at the very least, you will probably want a dummy /etc, a bind mount of /proc, and much of /lib inside the chroot.