I need a simple and easy way to jail users in their home directories in Oneiric. Do you have a simple configuration for jailing users, with full help, or some good web links?
I would be offering an online free public server with 10 to 20 GB free space. I don't know how many users. I want to give them SSH and SFTP so that they can connect through FileZilla.
Jailkit is a set of utilities that can limit user accounts to a specific directory tree and to specific commands. Setting up a jail is much easier using the Jailkit utilities that doing so 'by hand'. A jail is a directory tree that you create within your file system; the user cannot see any directories or files that are outside the jail directory. The user is jailed in that directory and it subdirectories.
Download & Install:
http://olivier.sessink.nl/jailkit/index.html#download
Setting up the jail
Now it’s time to set up the jail directory. Jailed users will see this directory as the root directory of the server. I chose to use /home/jail:
jk_init can be used to quickly create a jail with several files or directories needed for a specific task or profile, (click on it & read full detail ).
Add a user
Add a new user with a home directory and bash shell, and set the password:
Now it’s time to jail this user
use the following command:
Your
/etc/passwd
should contain something like this now:Enable bash
By using jk_cp the bash libraries are copied to the jail:
Edit
/home/jail/etc/passwd
replace this line:
with this:
Maintenance
By using
jk_update
updates on the real system can be updated in the jail.A dry-run will show what’s going on:
Without the -d argument the real update is performed. More maintenance operations can be found here.
(In case
/home/jail/opt
is missing, create it withmkdir -p /home/jail/opt/
And runjk_update -j /home/jail
again)Give access to other directories
You can mount special folders, that the jail user may acces now. E.g.:
Help Taken
You can not confine them to /home as they need access to the system binaries and bash and configuration files in /etc
IMO the easiest method of securing users is to use apparmor.
You make a hard link
You add jailbash to /etc/shells
You then assign jailbash to the users shell, and then write an apparmor profile for jailbash allowing minimal access.
You will have to write an apparmor profile yourself, but I have a profile you could potentially start with
http://bodhizazen.com/aa-profiles/bodhizazen/ubuntu-10.04/usr.local.bin.jailbash
It's difficult to guess what purpose you might want to accomplish. If it is to deny ssh/sftp while providing jailed access via FTP... easy:
Add to /etc/shells a new shell:
Add one line:
Save. For each user you want to deny ssh/sftp, change the user's shell:
Now userx cannot log in via ssh/sftp.
Install vsftpd:
Edit the config file:
And some changes....
Save. Restart vsftpd:
You could check out
rbash
as a shell for your users.Search for
RESTRICTED SHELL
sectionOr look on this page http://linux.die.net/man/1/bash