LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 05-20-2009, 11:51 AM   #1
vargstein
LQ Newbie
 
Registered: Apr 2009
Posts: 16

Rep: Reputation: 0
very simple chroot jail


Hi, i am trying to create a jail for a friend who is going to access some files.


i have read alot about things like ssh jailing and stuff, but i want to make the jail global for the user. he is going to have an ftp account also, i know i can chroot that (vsftpd).

the thing is that i want something like this

/home/theguy/[bin,var,usr....]

AND /home/theguy/target

which im going to:
Code:
mount -o bind /var/www/htdocs/somesubdir /home/theguy/target
so im thinking about making a script which will be his login script like

/etc/passwd:
Code:
theguy:x:1000:giggidy:/home/theguy:/path/to/script/below
and here is the login script:
Code:
#!/bin/bash

exec chroot /home/theguy/ /bin/bash

but the thing is that the chroot system call is for root only. so when theguy is executing his login script it will not work. so does anyone got any ideas on how i can do this. it will be very appreciated!

by the way the reason this guy is getting an account is because some html editing. i know there will be alot of permissions blablabla, and that he maybe will chroot into /target or something. im going to deal with this after im getting this to work.

again; your help is very appreciated!
 
Old 05-20-2009, 03:55 PM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Chroot jails are very well documented.

http://www.google.com/search?q=linux...-US:unofficial

You can easily mount the target directory inside the chroot jail.

Last edited by stress_junkie; 05-20-2009 at 03:56 PM.
 
Old 05-21-2009, 03:13 AM   #3
vargstein
LQ Newbie
 
Registered: Apr 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by stress_junkie View Post
Chroot jails are very well documented.

http://www.google.com/search?q=linux...-US:unofficial

You can easily mount the target directory inside the chroot jail.
yeah, but how can i allow a regular user to execute the chroot system call?
 
Old 05-23-2009, 04:12 PM   #4
phoenix_precedent
LQ Newbie
 
Registered: May 2009
Posts: 15

Rep: Reputation: 2
Have you investigated restricted shells?

You can set his default shell to rbash or rksh or the restricted version of whatever shell you use.
 
Old 05-23-2009, 05:08 PM   #5
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Quote:
Originally Posted by vargstein
Hi, i am trying to create a jail for a friend who is going to access some files.
Given the context (this person is a "friend"), can you not just give him a regular shell account and put some thought into your filesystem permissions? By contrast, for untrusted users, handing out shell accounts is a large can of worms and difficult to implement securely.

Quote:
Originally Posted by phoenix_precedent
Have you investigated restricted shells?
IMO, even this option is difficult to implement well. Too many programs (e.g. even staples like vi and less) allow shell commands to be run from within them, thus circumventing the restricted shell "restrictions".
 
Old 05-24-2009, 04:08 AM   #6
phoenix_precedent
LQ Newbie
 
Registered: May 2009
Posts: 15

Rep: Reputation: 2
Quote:
Originally Posted by anomie View Post
IMO, even this option is difficult to implement well. Too many programs (e.g. even staples like vi and less) allow shell commands to be run from within them, thus circumventing the restricted shell "restrictions".
Good point, but then again a secure chroot jail isn't exactly easy to setup either.

Does this friend really need shell access? If so, why?
 
Old 05-24-2009, 05:17 AM   #7
vargstein
LQ Newbie
 
Registered: Apr 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by phoenix_precedent View Post
Good point, but then again a secure chroot jail isn't exactly easy to setup either.

Does this friend really need shell access? If so, why?
he is just going to edit some html files in my /var/www/htdocs/subdir

this guy is a good friend in real life, so im very sure he don't have cruel intesions. I just wanted to try to do this in a very simple way without installing a lot of applications. something like i just change his login shell to a script that chroots into the jail and then i just mount -o bind a dir in the jail to the /var/www/htdocs/subdir.

i just want to learn how this works, but if i need alot of applications to do this, then i can just accept that he can read almost all the files in my system.

Thanks for all response!

EDIT: and by the way, this guy dosen't know anything about unix at all. so im actually just trying this so i can learn how to do it.

Last edited by vargstein; 05-24-2009 at 05:22 AM.
 
Old 05-24-2009, 05:41 PM   #8
phoenix_precedent
LQ Newbie
 
Registered: May 2009
Posts: 15

Rep: Reputation: 2
I thought it might be something like that.

He doesn't need shell access. He will likely be far more comfortable editing files on his own machine and uploading/downloading them to/from yours via sftp or similar than learning vi/emacs/whatever. I'm sure there are even graphical utilities for windows that handle sftp/scp.

Restricting his access to the htdocs directory should be trivial. Google is your friend ;-)

Best of luck,
Phoenix
 
Old 05-25-2009, 10:15 AM   #9
vargstein
LQ Newbie
 
Registered: Apr 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by phoenix_precedent View Post
I thought it might be something like that.

He doesn't need shell access. He will likely be far more comfortable editing files on his own machine and uploading/downloading them to/from yours via sftp or similar than learning vi/emacs/whatever. I'm sure there are even graphical utilities for windows that handle sftp/scp.

Restricting his access to the htdocs directory should be trivial. Google is your friend ;-)

Best of luck,
Phoenix
we are going to edit the same files, so i won't let him just upload the files after he has edited them, because if i have edited them then my changes will be lost. so using vi will give a warning that the file is already opened by someone else in vi. but i'll just giving him a regular enviroment then.

thanks for all response.
 
Old 05-27-2009, 05:59 AM   #10
phoenix_precedent
LQ Newbie
 
Registered: May 2009
Posts: 15

Rep: Reputation: 2
You could also use cvs or subversion, which has the added benefit of providing a nice history of your edits in case you want to roll back to a previous state.

-Phoenix
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Chroot jail Gimpy Linux - Software 10 05-07-2010 01:30 PM
Chroot jail pachanga Linux - General 12 09-26-2008 05:15 AM
Jail and chroot rogk Linux - Security 2 10-16-2005 02:20 AM
chroot jail etc. f1uke Linux - Security 5 08-24-2005 03:12 AM
chroot jail simon Linux - Security 3 08-05-2001 08:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 07:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration