user management - SSH Fails, /bin/bash: No such file or directory

  • matt ryan

    I have a user who is jailed.


    Subsystem sftp internal-sftp
    Match user matt
         ChrootDirectory %h
         X11Forwarding no
         AllowTcpForwarding no


    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 [email protected]
    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:
    Last login: Thu Mar 31 13:04:29 2011 from
    /home/matt/bin/bash: No such file or directory
    Connection to 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!

  • Answers
  • geekosaur

    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.

  • Related Question

    linux - chroot fails - cannot run command `/bin/bash': No such file or directory
  • Mike Atkinson

    I'm a chroot novice trying to make a simple chroot jail but am banging my head against the same problem time and time again... Any help would be massively appreciated

    I've created a directory /usr/chroot that I want to use as a jail and created subdirectories under it and copied the dependencies of /bin/bash into it:

    [root@WIG001-001 ~]# cd /usr/chroot/
    [root@WIG001-001 chroot]# ls
    [root@WIG001-001 chroot]# mkdir bin etc lib var home
    [root@WIG001-001 chroot]# ldd /bin/bash    =>  (0x00007fff99dba000)    => /lib64/ (0x00000037a2000000)    => /lib64/ (0x000000379fc00000)    => /lib64/ (0x000000379f800000)        
    /lib64/ (0x000000379f400000)
    [root@WIG001-001 chroot]# cp /lib64/ /usr/chroot/lib/  
    [root@WIG001-001 chroot]# cp /lib64/ /udr/csr/chroot/lib/  
    [root@WIG001-001 chroot]# cp /lib64/ /usr/chroot/lib/  
    [root@WIG001-001 chroot]# cp /lib64/ /usr/chroot/lib/  
    [root@WIG001-001 chroot]# cp /bin/bash bin  
    [root@WIG001-001 chroot]# pwd  
    [root@WIG001-001 chroot]# /usr/sbin/chroot .  
    /usr/sbin/chroot: cannot run command `/bin/bash': No such file or directory  
    it looks like the /bin/bash created under /usr/chroot is fine as the below works:  
    [root@WIG001-001 chroot]# su - nobody -s /usr/chroot/bin/bash  

    Can anyone give me any idea where to go from here?

  • Related Answers
  • Gilles

    The error message is misleading: /bin/bash: No such file or directory can mean either that /bin/bash doesn't exist, or that the dynamic loader used by /bin/bash doesn't exist. (You'll also get this message for a script if the interpreter on the #! line doesn't exist.)

    /bin/bash is looking for /lib64/ but you provided /lib/ Make /usr/chroot/lib64 a symbolic to lib or vice versa.

  • Mark Wagner

    Just do this: mv /usr/chroot/lib /usr/chroot/lib64