Change the root directory for apache, sshd and ftpd


 
Thread Tools Search this Thread
Special Forums IP Networking Change the root directory for apache, sshd and ftpd
# 1  
Old 07-05-2006
Bug Change the root directory for apache, sshd and ftpd

Helo !
I want to do something and I don't know where to start... I want to make a small web hosting server (just for me and a few friends) and for the sake of learning I'd like to make an account for every user. The thing is that I want everyone to log into the server and to be put in his home directory and that directory to be the root directory for that user.
I want to do this with ftpd, sshd and apache. All services for that user must let him in his home directory and he shouldn't be able to go anywhere else (excepting his subdirectories).

For ftpd it's simple... I use ftpchroot. I know that I can recompile the ftp server with it's built-in ls command, but I don't think it's necesarely.

For sshd, and apache I guess that I should do something with chroot... but I don't know what exactly to do... I mean, the root directory will differ for every user...

So, any ideeas or starting points to "acomplish" this it will be apreciated. Of course, any other point of view is welcomed as well.

The operating system I use is FreeBSD 5.4-RELEASE.

Thanks !
# 2  
Old 07-05-2006
Helo!
What you want is possible. I've never tryed it with Apache, but I suppose is the same.
Basically, you need to use a few tools:
  • chroot
  • sudo
  • ldd
The idea is to provide the user only what he needs, so that he can be jailed with chroot.
First, you need to create your chroot jail. To achieve this, you must create a directory structure on each user home as if it was "/". If you choose /home/user for "user" chroot jail, you will need to create inside, at least:
dev/
usr/
usr/bin
usr/lib
var/
etc/
sbin/

After that, you have to copy there the tools and libs the user is going to use. You could use "ldd" to guess which libs each binary needs, and copy them to its appropriate directory. You may want to copy a shell, and some basic commands (cat, grep, more, etc) with the libraries they need to run.
For example, in my AIX box:

Code:
$cp /usr/bin/ksh /home/user/usr/bin/ksh
$ldd /usr/bin/ksh 
/usr/bin/ksh needs:
         /usr/lib/libc.a(shr.o)
         /unix
         /usr/lib/libcrypt.a(shr.o)
$cp /usr/lib/libc.a /home/user/usr/lib
$cp /usr/lib/libcrypt.a /home/user/usr/lib

Perhaps you would need to create some device files in /home/user/dev. Do not use cp for this, instead, use the appropriate command. In may case (AIX), "mknod".

You will also need to create an etc/passwd and an etc/group in your chroot.

Now you need a "special shell" which put the user into the jail when he/she logs in.
For instance, create a /bin/chroot_shell.sh like this:

Code:
if [ "$1" = "-c" ]; then
        sudo /usr/sbin/chroot /home/$USER /bin/su - $USER $*
else
        sudo /usr/sbin/chroot /home/$USER /bin/su - $USER
fi

As you can see you will need to configure "sudo" for this to work. Use "visudo" to add a line like this:

Code:
user ALL=NOPASSWD:/usr/sbin/chroot /home/user /bin/su - user*

Next, change "user"'s shell into /bin/chroot_shell.sh in /etc/passwd

After that, And add a line in /home/user/etc/passwd like:
Code:
user:!:203:1::/:/usr/bin/ksh

NOTICE, you must have copyed /usr/bin/ksh to /home/user/usr/bin/ksh along with every lib ksh needs.

Well, these are, more or less, the steps you should follow, but most probably I forgot something or made a mistake... I've written this by heart Smilie

I hope it helps.
# 3  
Old 07-05-2006
Well... it sounds pretty simple... I'll try later and I hope it is going to work.
Thanks a lot for your answer and for the time spent writing this mini-tutorial Smilie
# 4  
Old 07-05-2006
Quote:
Originally Posted by Sergiu-IT
Well... it sounds pretty simple... I'll try later and I hope it is going to work.
Thanks a lot for your answer and for the time spent writing this mini-tutorial Smilie
Yes, it's really simple Smilie
I think this is valid also for apache... I've tested it in Linux, AIX and Solaris with ftp, telnet, ssh and have no problem... Besides it is easy to automate with scripts if you ar planning to have a large amount of users Smilie
I have a more detailed tuto written by me in spanish, but this is an english forum, hehehe...
Good luck with the test!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Can a root role change the root password in Solaris 10?

i do not have root on a solairs 10 server , however i do have the root role, i was wondering if I can change the root password as a a role with the passwd command? I have not tried yet. and do i have to use the # chgkey -p afterwards? i need to patch is why i am asking. thanks (1 Reply)
Discussion started by: goya
1 Replies

2. Ubuntu

Root access that can't change root password?

We are having a little problem on a server. We want that some users should be able to do e.g. sudo and become root, but with the restriction that the user can't change root password. That is, a guarantee that we still can login to that server and become root no matter of what the other users will... (2 Replies)
Discussion started by: 244an
2 Replies

3. Shell Programming and Scripting

Configuring Apache an php Directory root.

Hi , I have installed apache and configured Document root as /home DocumentRoot "/home" The files under home directory is listed on the web server, i have one text file under "/home/test/1.txt" i can view the file when i set DocumentRoot to /home. But when i change Document root to ... (1 Reply)
Discussion started by: asak
1 Replies

4. UNIX for Dummies Questions & Answers

etc/ftpd/ftpusers & philosophy of disabling root

we don't have root in our /etc/ftpd/ftpusers and we are getting some pushback from the external auditors about this - specifically as a security risk if a "sniffer" were to catch roots password at the ftp. What do most shops do - disable ftp for root? What do you do to get things to the... (3 Replies)
Discussion started by: LisaS
3 Replies

5. Solaris

root can not change the permission of old oracle archive directory in solaris 8

I am using oracle 9i with sun solaris 8 on Sun E 250 server.earlier we are taking backup of oracle archive files on /orabackup directory.in which archive file are stored with ...arc.Z extension. now we have changed the archive backup directory.now when we are trying to delete earlier directory... (3 Replies)
Discussion started by: mahanalok
3 Replies

6. UNIX Desktop Questions & Answers

how to check if a file ftpd to mainframe was actually ftpd

Hi All, I am ftping a file from unix to mainframe. Now the problem arises that i want to check if the file was ftpd or not. Is there any way i could do this? (4 Replies)
Discussion started by: vikas.rao11
4 Replies

7. Solaris

sshd (openssh) on SunOS without root privileges

Hi, I've just managed to install openssh in my home directory on a server I have access to by using --prefix=$HOME/local after ./configure. Another thing I was having trouble with without root access was privilege separation, so I disabled that in my sshd_config. However, when I run... (10 Replies)
Discussion started by: sayeo
10 Replies

8. Solaris

running sshd server from home directory without root access

Hi, I managed to install openssh from source on my home directory on a server I don't have root access to. I had problems with privilege separation because of permissions initially so I disabled it in sshd_config. But when I run sshd from where I installed it by doing ~/local/sbin/sshd, nothing at... (0 Replies)
Discussion started by: sayeo
0 Replies

9. UNIX for Dummies Questions & Answers

issues involving sshd, display and apache.

I have a rather peculiar problem in the past 2 weeks. I have a network setup with a linux box acting as a gateway (It is exposed to the internet). Also, there are 2 additional machines that are connected to the gateway (and are not exposed to the outside world). (The gateway has a NAT setup to... (5 Replies)
Discussion started by: ceeeyem
5 Replies

10. UNIX for Dummies Questions & Answers

FTPD, CHROOT, SMF and non-root user

Hello I am trying to configure WU-FTPD on Solaris 10 to do the following: Using the -r parameter to in.ftpd, I am running the FTP demon within a CHROOT jail (/export/ftp). The FTP service is also being controlled by SMF. This seems to work fine. However, one of the requirements I have is to... (2 Replies)
Discussion started by: CowsUdders
2 Replies
Login or Register to Ask a Question