Bftpd Tutorial by Daniel Zilli

If you need setup a FTP server, you came to the right place.



0.1. Introdution

Here you will learn how to setup a secure, simple and efficient FTP server. Of course I am talking about Bftpd, this great software maintained by Jesse Smith. This peace of art is all I need to make my FTP server run in a sweet way, and hope that the same happens to you. This document will not teach you how FTP works, here it is assumed that you know how things work and just want to setup a FTP server using the Bftpd, but if you are new, don't panic, I will explain every step in detail.

0.2. Installation

The first thing you need is the package itself (of course!). Some distributions already have the package, so my advice is for you to look first if your distribution has the package. If your distro doesn't have it or you don't know or you want the fast way, let's compile, for ourselves the program. Compiling this software is fast and easy. But before compile let me say that Jesse provide two packages to us, the source package and the RPM package, so if your distribuition use the RPM packager manager, your chances to have the package ready to you is very big, but don't worry, the RPM instalation we will see later. Now let's have fun!

Note-1: I will assume that you are working in the linux console.
Note-2: Replacing 2.x by the correct version number.
Note-3: Be root to avoid any problem of permissions.
Note-4: The commands you need type are in italic.
Note-5: You have to copy bftpd.conf from the source directory to /etc manually if you are upgrading from a previous version, as 'make install' does not overwrite your existing configuration.

Bftpd, has two trees of development. The stable and the development one. Here I will use the stable version. One note: The word "development" in the Bftpd world, doesn't mean "no test", "let's see what happens" or "I am playing with the code". Even the development version is very stable and ready to use, so if you want use go ahead.


Download

First, choice a place to put the source file. To make the download please visit this page the Bftpd website and go to the download section http://bftpd.sourceforge.net/download.html and choose the "bftpd package source" for "The latest stable version of bftpd is 2.x".


Compile

After you download the source is time to extract the content. To make this, go to the direcoty you saved your bftpd source and type:

tar xzf bftpd-2.x.tar.gz

Good. Now that the content of the package is avalible to us, let's get into the recently created directory.

cd bftpd-2.x

Now we are inside the source directory, you can see around. But we don't have time to lose so let's compile this now. This is made with three stpes.

Step 1 - Configure the source to be compile

./configure --prefix=/usr

Step 2 - Compiling the source

make

Step 3 - Installing the program

make install

Sumary

Just to keep a track for what we did until now:

	./configure --prefix=usr
	make
	make install

Note-6: If you want to use the 'tar.gz on-the-fly' feature of Bftpd, you must grab the source code of the program "pax" and extract it into a subdirectory of the Bftpd source directory. Then, instead of doing "./configure", do "./configure --enable-pax=pax-sourcedir --enable-libz". You must also have the library libz and its header file, /usr/include/zlib.h.


RPM

So, if your distribution is a RPM based, congratulations because a RPM file is waiting for your download in the same place where you got the sources. Just choose the package "bftpd RPM package" and go download ! Installing RPM

To install a RPM file is very easy, just type:

rpm -ivh bftpd-2.x-1.i386.rpm

Congratulations!! If everything went well, you have the bftpd installed in your sytem.

0.3. Configuring

Before running the server, is time to configure it. Now is the key point, but don't have any secret here. All configurations options are controlled from the bftpd.conf file, that reside at /etc. In a first sight, you don't need change anything, but know what is really happening is always a good thing. The bftpd.conf is a very explained file, all the variables are explained in detail, so it is easy to understand. If you want to know how my bftpd.conf is configured, take a look:

  global {
    DENY_LOGIN="no"
    PORT="21"
    PASSIVE_PORTS="0"
    DATAPORT20="no"
    ADMIN_PASS="x"
    PATH_BFTPDUTMP="/var/run/bftpd/bftpdutmp"
    XFER_BUFSIZE="2048"
    CHANGE_BUFSIZE="no"
    XFER_DELAY="0"
    SHOW_HIDDEN_FILES="no"
    SHOW_NONREADABLE_FILES="no"
    ALLOW_FXP="no"
    CONTROL_TIMEOUT="300"
    DATA_TIMEOUT="30"
    RATIO="none"
    ROOTDIR="%h"
    UMASK="022"
    LOGFILE="/var/log/bftpd.log"
    HELLO_STRING="ftp at %i ready."
    AUTO_CHDIR="/"
    AUTH="PASSWD"
    RESOLVE_CLIENT_IP="no"
    MOTD_GLOBAL="/etc/ftpmotd"
    MOTD_USER="/.ftpmotd"
    RESOLVE_UIDS="yes"
    DO_CHROOT="yes"
    LOG_WTMP="yes"
    BIND_TO_ADDR="any"
    PATH_FTPUSERS="/etc/ftpusers"
    AUTH_ETCSHELLS="no"
    ALLOWCOMMAND_DELE="no"
    ALLOWCOMMAND_STOR="yes"
    ALLOWCOMMAND_SITE="no"
    HIDE_GROUP=""
    QUIT_MSG="See you later..."
    USERLIMIT_GLOBAL="0"
    USERLIMIT_SINGLEUSER="0"
    USERLIMIT_HOST="0"
    GZ_UPLOAD="no"
    GZ_DOWNLOAD="no"
  }
  
  user ftp {
  #Any password fits.
   ANONYMOUS_USER="yes"
  }
  
  user anonymous {
  #If the client wants anonymous, ftp is taken instead.
   ALIAS="ftp"
  }
  
  user root {
   DENY_LOGIN="Root login not allowed."
  }

0.4. Running

Our Bftpd is now installed and configured. So, now we need prepare Bftpd to start, and we can do this in two ways. Inetd or by script. I spoke Greek now ! :-) Don't worry, is not Greek is Free Software!

If you want inetd mode, add the following to your /etc/inetd.conf:

ftp stream tcp nowait root /usr/sbin/bftpd bftpd

But, If you want inetd mode with xinetd, add the following to your /etc/xinetd.conf:

      service ftp
      {
          disable         	  = no
          socket_type             = stream
          wait                    = no
          user                    = root
          server                  = /usr/sbin/bftpd
          log_on_success          += HOST PID
          log_on_failure          += HOST
          nice                    = 10
      }

In this mode, the program inetd will take care in start and stop the bftpd.

But to be honest, I prefer the standalone mode. For me, seen that I have more control. Here is the command to execute in standalone mode:

/usr/sbin/bftpd -d

Executing the above command in the prompt you will have the Bftpd working. But isn't comfortable. Because every time that we want the server start, we need to execute that command. Ok, you can put the command in some file or script to have it automaticly start, but to stop or restart you need kill the command and start by hand again. So to avoid all this and made my life easier I have this little script that do all the work for me.

  ---------------
  #!/bin/bash
  
  case "$1" in
    'start')
      echo "Starting bftpd Server"
      /usr/sbin/bftpd -d
      ;;
    'stop')
      echo "Stopping bftpd Server"
      killall bftpd
      ;;
    'restart')
      $0 stop
      sleep 1
      $0 start
      ;;
    *)
  echo "usage: $0 {start|stop|restart}"
  esac
  ---------------

You have to make this script executable and put it in your /etc/rc.d or /etc/init.d

That's all! Now you have your Bftpd configured and working.

Congratulations !

0.5. Things that others tutorials don't say to you

All the information above is enough to start using a FTP server if you are a intermediate/advanced user, but for the beginners that will follow exactly every step here, there are some items that we need leave very clear.

Firewall: It's very important you don't forget the rules to allow FTP traffic pass through your firewall. Usually the follow rules is enough:
IPTABLES -A INPUT -p tcp --dport 21 -j ACCEPT

But this is only an example. PLEASE STUDY IPTABLES, YOU WILL ALWAYS NEED IT.

User account: Ok...you now have your FTP server, but how can I access? Simple! Just create a normal user account in your Linux system. When we create the user account the home directory is created too. So when the user access our FTP, she/he will enter with the login and password, if everything goes well, the user will fall into your home directory (this can be setup to a different place at bftpd.conf).

Ip or Domain: If you going to make available your FTP to the world, you don't need have a domain, just a valid IP. To use your domain to access FTP, you must have the DNS configurated...and this is another story.

0.6. The End

I think is that ! I hope in some way I helped anyone. Bftpd is very simple to use, no secrets. But if you have any doubt, please email me zilli.daniel@gmail.com or visit the bftpd.sf.net website and contact Jesse Smith, bftd's maintainer.

0.7. Credits

Author: Daniel Zilli zilli.daniel@gmail.com

Thanks to: Jesse Smith jessefrgsmith@yahoo.ca (current maintainer) and Max-Wilhelm Bruker brukie@gmx.net (original developer of bftpd).

0.8. Change Log

	Version 19 August 2007
		- Intial release.
	Version 18 April 2008
		- I am back !
		- Change from HMTL to XHTML document.
		- Fix a lot of typos.
		- Make the text more clear.

This is text is under GNU Free Documentation License version 1.2.