topics that matter; ideas worth sharing

share a tip, submit a link, add something new

Unix Tip: Creating a chrooted FTP account

November 6, 2007, 12:33 PM —  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.

 

ITworld.com

I like it!
Post a comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
Resources
White Paper

Symantec Backup Exec 12 and Backup Exec System Recovery 8 deliver industry leading Windows data protection and system recovery. Download this whitepaper to find out the top reasons to upgrade and how to get continuous data protection and complete system recovery.

Webcast

Data and system loss — from a hard drive failure, malicious attack, natural disaster, or simple human error — can happen anytime. Don’t leave your business vulnerable. Make sure you have a secure recovery strategy in place. Symantec's latest backup and system recovery technology can efficiently restore critical applications, individual emails and documents and even restore your entire system in minutes in the event of a loss.

White Paper

Businesses face a growing challenge to ensure that the IT environment is properly protected. Backup Exec 12 integrates with other applications in the Symantec family of products, to complement your current data protection strategy, keep your data securely backed up and make it recoverable when you need it most.

Free stuff
Featured Sponsor

Get a broad understanding of important regulations and how you can make sure your site is in adherence.





Learn how VeriSign SGC-enabled SSL Certificates can help improve site security and customer confidence in the free white paper, "How to Offer the Strongest SSL Encryption." In this paper you will learn the differences between weak and strong encryption and what they mean for your site's performance.

Get VeriSign's free white paper: "The Latest Advancements in SSL Technology" and learn about the benefits of strong SSL encryption, Extended Validation (EV) SSL and security trust marks and what these SSL offerings can do for your site.

Now with Extended Validation (EV) SSL available from VeriSign, you can show your customers that they can trust your site. Learn about EV SSL benefits in this free VeriSign white paper.

More Resources