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

16
2014-04
  • matt ryan

    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 [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:  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!

  • 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        
    linux-vdso.so.1 =>  (0x00007fff99dba000)        
    libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00000037a2000000)        
    libdl.so.2 => /lib64/libdl.so.2 (0x000000379fc00000)        
    libc.so.6 => /lib64/libc.so.6 (0x000000379f800000)        
    /lib64/ld-linux-x86-64.so.2 (0x000000379f400000)
    
    [root@WIG001-001 chroot]# cp /lib64/libtinfo.so.5 /usr/chroot/lib/  
    [root@WIG001-001 chroot]# cp /lib64/libdl.so.2 /udr/csr/chroot/lib/  
    [root@WIG001-001 chroot]# cp /lib64/libc.so.6 /usr/chroot/lib/  
    [root@WIG001-001 chroot]# cp /lib64/ld-linux-x86-64.so.2 /usr/chroot/lib/  
    [root@WIG001-001 chroot]# cp /bin/bash bin  
    [root@WIG001-001 chroot]# pwd  
    /usr/chroot  
    [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  
    -bash-4.0$ 
    

    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/ld-linux-x86-64.so.2 but you provided /lib/ld-linux-x86-64.so.2. Make /usr/chroot/lib64 a symbolic to lib or vice versa.

  • Mark Wagner

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