Tuesday, October 12, 2004

A small how-to on how to chroot a user in bash shell

I know i have been bad in promises but this is now to chroot in bash shell.

The first and foremost is that you become the root or else use sudo on each step.

A little assumption before i start :

juser : username of the user who logs in to the chrooted BASH shell
jailed : group the above user belongs to :)

1. Creat a new shell file as

/bin/chroot-sh

Contents of /bin/chroot-sh are

#!/bin/bash
if [ "$1" = "-c" ];
then i=0; PARAMS=""; for param in $*;
do if [ $i -gt 0 ];
then PARAMS="$PARAMS $param";
fi let i++; done;
sudo /usr/sbin/chroot /home/$USER /bin/su - $USER -c "$PARAMS"
else
sudo /usr/sbin/chroot /home/$USER /bin/su - $USER fi;

2 .Add the user specifying the shell like

#useradd -d /home/juser -s /bin/chroot-shell juser

3. Creat the directories for the user sees as below.
mkdir /home/juser
mkdir /home/juser/etc
mkdir /home/juser/dev
mkdir /home/juser/bin
mkdir /home/juser/lib
mkdir /home/juser/usr
mkdir /home/juser/usr/bin
mkdir /home/juser/home
chown juser:jailed /home/juser/home

4. A dummy password and group file for the user
/home/juser/etc/passwd
root:x:0:0::/:/bin/bash
juser:x:1004:1004::/home:/bin/bash

/home/juser/etc/group

root:x:0:
jailed:x:1004:

5. Coping the required files and linking them.

cp /bin/bash /home/juser/bin/

ldd /bin/bash

cp /bin/su /home/juser/bin/
ldd /bin/su

6. Install fileutils aka file manupulation commands

cd /bin;
cp ln ls rm mv cp du /home/juser/bin/

thats it you can give him telnet / ssh access now

Hope it helps you all .

Till the next post take care and have a great time.

4 Comments:

At 2/14/2009 02:46:00 AM, Anonymous simranjitsingh said...

thankx dear i will try it

 
At 10/25/2009 09:18:00 PM, Blogger Adi said...

Thank you for sharing.
Oes Tsetnoc | Mengembalikan Jati Diri Bangsa | Kenali dan Kunjungi Objek Wisata di Pandeglang | Oes tsetnoc | Online Marketing | Electronics Gadgets | etips solution | Travel Guide

 
At 10/29/2009 02:33:00 PM, Blogger The Jack said...

Thanks ever so much, very useful article. If you do not mind, please visit my article related to pandeglang district in Banten, Indonesia at Kenali dan Kunjungi Objek Wisata di Pandeglang or Kenali dan Kunjungi Objek Wisata di Pandeglang second and also Kenali dan Kunjungi Objek Wisata di Pandeglang Objek Wisata Air Terjun Curug Gendang and Kesenian Debus, Sejarah dan Ciri Khas Wisata Banten and our hard work at Kerja Keras Adalah Energi Kita that's right Kerja Keras Adalah Energi Kita, and Kenali dan Kunjungi Objek Wisata di Pandeglang Memasuki Babak Akhir also Objek Wisata Taman Wisata Alam Carita, Kenali dan Kunjungi Objek Wisata di Pandeglang, or Kenali dan Kunjungi Objek Wisata di Pandeglang, also Kenali dan Kunjungi Objek Wisata di Pandeglang, or Kenali dan Kunjungi Objek Wisata di Pandeglang, also Kenali dan Kunjungi Objek Wisata di Pandeglang, or Kenali dan Kunjungi Objek Wisata di Pandeglang, also Kenali dan Kunjungi Objek Wisata di Pandeglang, or Kenali dan Kunjungi Objek Wisata di Pandeglang, very smart thank you!

 
At 11/15/2009 09:35:00 AM, Blogger Daniela said...

Find your great Travel News and sing the songs at Free Song Lyric or you can watch the drama at Korea Drama Online one of great korea drama is A Love to Kill if you go to travel to Indonesia learn Learn Indonesia Language first! And find your home cari rumah or make a blog Belajar membuat Blog find your home again rumah dijual and again at jual rumah then if you want buy a new laptop see the Laptop Price List or you can buy a New Blackberry and then take care your Health & Jewerly.

 

Post a Comment

<< Home