Add command like vi, vim to chrooted SSH user



i followed article Debian/Ubuntu Linux: Restrict an SSH user session to a specific directory by setting chrooted jail and created ssh chrooted jailed ssh account succesullly. but, now, the problem is.
my user chrooted can do nothing else show file listing and change directory.
how to add command like vi or vim, or chmod for chrooted user.?
using ubuntu 14.04 server.
thanks !


You need to copy vi/vim binary to chrooted directory and related files. For example if chrooted jail is at /home/users as root:

mkdir -p $D/usr/bin
cp -a /usr/bin/vim $D 

Next get libs needed to run vim:

ldd /usr/bin/vim

You will get a list of libs as follows: =>  (0x00007ffe9abd4000) => /usr/lib/x86_64-linux-gnu/ (0x00007f2848f22000) => /usr/lib/x86_64-linux-gnu/ (0x00007f2848c17000) => /usr/lib/x86_64-linux-gnu/ (0x00007f2848a0a000) => /usr/lib/x86_64-linux-gnu/ (0x00007f28487bc000) => /usr/lib/x86_64-linux-gnu/ (0x00007f28484ab000) => /usr/lib/x86_64-linux-gnu/ (0x00007f2848287000) => /usr/lib/x86_64-linux-gnu/ (0x00007f2847eec000) => /usr/lib/x86_64-linux-gnu/ (0x00007f2847c98000) => /lib/x86_64-linux-gnu/ (0x00007f2847984000) => /usr/lib/x86_64-linux-gnu/ (0x00007f284777c000) => /usr/lib/x86_64-linux-gnu/ (0x00007f2847561000) => /usr/lib/x86_64-linux-gnu/ (0x00007f28472f8000) => /usr/lib/x86_64-linux-gnu/ (0x00007f2846fbf000) => /lib/x86_64-linux-gnu/ (0x00007f2846c69000) => /lib/x86_64-linux-gnu/ (0x00007f2846a40000) => /lib/x86_64-linux-gnu/ (0x00007f2846818000)
... => /usr/lib/x86_64-linux-gnu/ (0x00007f283cb91000) => /usr/lib/x86_64-linux-gnu/ (0x00007f283c96a000) => /lib/x86_64-linux-gnu/ (0x00007f283c65c000) => /lib/x86_64-linux-gnu/ (0x00007f283c436000) => /usr/lib/x86_64-linux-gnu/ (0x00007f283c21e000) => /lib/x86_64-linux-gnu/ (0x00007f283c009000)

You need to create those dir and copy files too. For example:

mkdir $D/lib
mkdir $D/usr/lib
cp -a  /lib/x86_64-linux-gnu/ $D/lib

Repeat steps for all files produced by ldd. For more info see chroot command examples here

Chroot method gets compilcated. So I suggest you take a look at lxd/lxc:

Another option is just to create containers using lxd. See:

  1. How to install and setup LXC (Linux Container) on Fedora Linux 26
  2. How to install LXD container hypervisor on Ubuntu 16.04 LTS
  3. How to install LXD container under KVM or Xen virtual machine