open.itworld.com
  Search  
Security Home Page Security Webcasts Security White Papers Security Newsletters Security News Open Topics Careers ITworld Voices ITwhirled The Security site of ITworld.com

Unix Tip: Creating a chrooted FTP account

ITworld 11/06/2007

Sandra Henry-Stocker, ITworld.com

Send in your Unix questions today! | See additional Unix tips and tricks

Often referred to as a "chroot jail" or a "padded cell" because users cannot escape from the directories into which they are put when they log in, the basic concept of a "chroot" (change root) configuration is that a user's working view of the system's file system is dramatically modified so that only some particular directory and its contents is visible, making it appear to be the entire system. In fact, the chroot process involves setting up a mini-OS environment that looks and acts as if it were largely independent of the rest of the system (though, of course, it is not). This allows jailed users to issue an essential set of commands -- whatever commands are required for them to do the work that their jail cell was meant to accomplish. For example, jailed users might need to change directories. If so, the cd command needs to be added to their limited file system. They might need to list files. If so, they need a copy of the ls command.

Providing only the basic commands that jailed users need is not quite enough, however. While it might not be obvious, most basic Unix commands are incomplete in themselves. To function, they make use of a number of shared library files. If your jailed users don't have access to these shared library files, they will not be able to make use of commands like cd and ls, even if you provide these binaries in their a /usr/bin directory. The commands will issue errors attesting to the missing library files and fail.

Each chrooted environment, therefore, needs to contain many of the same directories you would expect to find in the root file system on a typical Unix system -- /usr/bin, /usr/lib, /etc and so on. The commands and libraries you need for any chrooted environment depend on the nature of the application that it will be supporting.

In particular, creating a chrooted ftp site involves both creating a working chrooted environment and then ensuring that your ftp server enforces the restrictions.

FTP-Only Setup

When you are setting up an account that is only to be used for uploading and downloading files, you want to be sure that the account cannot be accessed in any other way. To make an account ftp-only, you need to do two things. First, you assign the account a shell that doesn't permit normal login. You can do this by setting the jailed user's shell to /bin/false or you can create an executable to serve as the user's shell. I prefer to create my own shell by compiling code like this:

main () {
    printf("+---------------------------------------+\n");
    printf("| This account only provides ftp access |\n");
    printf("+---------------------------------------+\n");
    exit();
}
This "exit only" shell displays an explanatory message to the user and exits. The exit disconnects him from the system. If you use /bin/false, no message is displayed; the user is simply logged off. To permit ftp once the /bin/false or /bin/exitonly "shell" is specified as the user's shell in the /etc/passwd file, you have to add the path for the file to your /etc/shells file -- the file that specifies which shells are allowed to be used with ftp. At this point, the jailed user can ftp files to and from the system, but cannot log in with telnet or ssh. If you test the account by attempting to switch user, you should see something like this:

# su - grilli
+---------------------------------------+
| This account only provides ftp access |
+---------------------------------------+
The second part of the process involves setting up the user's chrooted environment. Once he logs in, after all, you do not want him to be able to cd to directories outside the intended jail. This part of the process involves a lot of file copying and permission setting and is described in a section below.

The last and final step is getting your ftp server to treat the ftp-only user as an untrusted (i.e., jailed) guest. In other words, it has to keep the user in the restricted environment established in part two of the setup process. For me, this involved a simple change to wuftpd's configuration file (ftpaccess).

To jail a user or set of users in the ftpaccess file, you need to identify each user individually as a guestuser or the users' group (as defined in the /etc/group) file as a guestgroup. For example, if your jailed users are members of a guests group (e.g., "guests::8080:" in the /etc/group file), you would use a line like this in your ftpaccess file:

guestgroup guests
If you prefer to list your jailed users individually, you would use a syntax like this:

guestuser sal loretta danny grilli
When one of your jailed users makes an ftp connection to your system, he will see something like this:

> ftp chrooting.host.net
Connected to chrooting.host.net.
220 owl FTP server (Version wu-2.6.2(6) Fri Apr 8 02:34:57 EDT 2004) ready.

User (owl.host.net:(none)): grilli
331 Password required for grilli.
Password:
230 User grilli logged in.  Access restrictions apply.
Note the "Access restrictions apply" warning.

If a cd command is supplied (e.g., if you have set up separate downloads and uploads directories and provided a cd and ls commands), the chrooted environment will allow the user to move around in his limited file space:

ftp> cd downloads
250 CWD command successful.
ftp> ls
200 PORT command successful.
150 Opening ASCII mode data connection for file list.
download.me.file
download.me2.file
If the user attempts to cd to your root file system, on the other hand, he will actually be moving into the root directory for his chrooted file system.

ftp> cd /
250 CWD command successful.
ftp> ls
200 PORT command successful.
550 No files found.
ftp>
This is the effect you want. Chrooted users can't go wandering around the file system looking at downloading files they don't need to see.

Next week, we'll look at techniques and scripts for setting up a chrooted environment.

On this topic

 

Sandra Henry-Stocker has been administering Unix systems for more than 18 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She currently works for TeleCommunication Systems, a wireless communications company, in Annapolis, Maryland, where no one else necessarily shares any of her opinions. She lives with her second family on a small farm on Maryland's Eastern Shore. Send comments and suggestions to bugfarm@gmail.com.




Sponsored Links

Sign up for a Microsoft Dynamics® CRM WEBCAST
Hear globally recognized leaders in customer strategy discuss the importance and evolution of CRM.
Sun Microsystems' - FREE 60 DAY TRIAL OFFER!
Test Sun's Newest Servers BEFORE YOU BUY. Plug Them In With Access To Full Technical Support.
100% Web Based Help Desk Software
Easy to use, customizable to meet your needs, powerful and scalable. Free online demo. Try it today!
Sign up for a Microsoft Dynamics® CRM WEBCAST
Hear globally recognized leaders in customer strategy discuss the importance and evolution of CRM.
Used and Refurbished HP ProCurve Switches
Lifetime Warranties, Professional Testing & Shipping on all HP Equipment Purchases!
» Buy a link now

Advertisements
Sponsored links
Locate Hidden Software on business PCs with this free tool
Bring harmony to your mix of UNIX-Linux-Windows computing environments
Top 5 Reasons to Combine App Performance and Security
KODAK i1400 Series Scanners stand up to the challenge
 Home   Open source  Operating systems  Unix
www.itworld.com    open.itworld.com     security.itworld.com     smallbusiness.itworld.com
storage.itworld.com     utilitycomputing.itworld.com     wireless.itworld.com

 
Contact Us   About Us   Privacy Policy    Terms of Service   Reprints  

CIO   Computerworld   CSO   GamePro   Games.net   IDG Connect   IDG World Expo   Infoworld   ITworld   JavaWorld   LinuxWorld  MacUser   Macworld   Network World   PC World   Playlist  

Copyright © Computerworld, Inc. All rights reserved

Reproduction in whole or in part in any form or medium without express written permission of Computerworld Inc. is prohibited. Computerworld and Computerworld.com and the respective logos are trademarks of International Data Group Inc.