HTML Tags

<html> – Begins your HTML document.

<head> – Contains information about the page such as the TITLE, META tags for proper Search Engine indexing, STYLE tags, which determine the page layout, and JavaScript coding for special effects.

<title> – The TITLE of your page. This will be visible in the title bar of the viewers’ browser.

</title> – Closes the HTML <title> tag.

</head> – Closes the HTML <head> tag.

<body> – This is where you will begin writing your document and placing your HTML codes.

</body> – Closes the HTML <body> tag.

</html> – Closes the <html> tag.

HTML Tags Chart

To use any of the following HTML tags, simply select the HTML code you’d like and copy and paste it into your web page.

Tag Name Code Example Browser View
<!– comment <!–This can be viewed in the HTML part of a document–> Nothing will show (Tip)
<a – anchor <a href=“http://www.domain.com/”&gt;
Visit Our Site</a>
Visit Our Site (Tip)
<b> bold <b>Example</b> Example
<big> big (text) <big>Example</big> Example (Tip)
<body> body of HTML document <body>The content of your HTML page</body> Contents of your web page (Tip)
<br> line break The contents of your page<br>The contents of your page The contents of your web page
The contents of your web page
<center> center <center>This will center your contents</center> This will center your contents
<dd> definition description <dl>
<dt>Definition Term</dt>
<dd>Definition of the term</dd>
<dt>Definition Term</dt>
<dd>Definition of the term</dd>
</dl>
Definition Term
Definition of the term
Definition Term
Definition of the term
<dl> definition list <dl>
<dt>Definition Term</dt>
<dd>Definition of the term</dd>
<dt>Definition Term</dt>
<dd>Definition of the term</dd>
</dl>
Definition Term
Definition of the term
Definition Term
Definition of the term
<dt> definition term <dl>
<dt>Definition Term</dt>
<dd>Definition of the term</dd>
<dt>Definition Term</dt>
<dd>Definition of the term</dd>
</dl>
Definition Term
Definition of the term
Definition Term
Definition of the term
<em> emphasis This is an <em>Example</em> of using the emphasis tag This is an Example of using the emphasis tag
<embed> embed object <embed src=”yourfile.mid” width=”100%” height=”60″ align=”center”> (Tip)
<embed> embed object <embed src=”yourfile.mid” autostart=”true” hidden=”false” loop=”false”>
<noembed><bgsound src=”yourfile.mid” loop=”1″></noembed>

Music will begin playing when your page is loaded and will only play one time. A control panel will be displayed to enable your visitors to stop the music.

<font> font <font face=”Times New Roman”>Example</font> Example (Tip)
<font> font <font face=”Times New Roman” size=”4″>Example</font> Example (Tip)
<font> font <font face=”Times New Roman” size=”+3″ color=”#ff0000″>Example</font> Example (Tip)
<form> form <form action=”mailto:you@yourdomain.com”>
Name: <input value=”” size=”10″><br>
Email: <input value=”” size=”10″><br>
<center><input></center>
</form>
Name:  (Tip)
Email: 
<h1>
<h2>
<h3>
<h4>
<h5>
<h6>
heading 1
heading 2
heading 3
heading 4
heading 5
heading 6
<h1>Heading 1 Example</h1>
<h2>Heading 2 Example</h2>
<h3>Heading 3 Example</h3>
<h4>Heading 4 Example</h4>
<h5>Heading 5 Example</h5>
<h6>Heading 6 Example</h6>
<head> heading of HTML document <head>Contains elements describing the document</head> Nothing will show
<hr> horizontal rule <hr /> Contents of your web page (Tip)


Contents of your web page

<hr> horizontal rule <hr width=”50%” size=”3″ /> Contents of your web page


Contents of your web page
<hr> horizontal rule <hr width=”50%” size=”3″ noshade /> Contents of your web page


Contents of your web page
<hr>
(Internet
Explorer)
horizontal rule <hr width=”75%” color=”#ff0000” size=”4″ /> Contents of your web page


Contents of your web page
<hr>
(Internet
Explorer)
horizontal rule <hr width=”25%” color=”#6699ff” size=”6″ /> Contents of your web page


Contents of your web page
<html> hypertext markup language <html>
<head>
<meta>
<title>Title of your web page</title>
</head>
<body>HTML web page contents
</body>
</html>
Contents of your web page
<i> italic <i>Example</i> Example
<img> image <img src=”Earth.gif” width=”41″ height=”41″ border=”0″ alt=”text describing the image” /> (Tip)
<input> input field Example 1:

<form method=post action=”/cgi-bin/example.cgi”>
<input type=”text” size=”10″ maxlength=”30″>
<input type=”Submit” value=”Submit”>
</form>

Example 1: (Tip)

<input>
(Internet Explorer)
input field Example 2:

<form method=post action=”/cgi-bin/example.cgi”>
<input type=”text” style=”color: #ffffff; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72a4d2;” size=”10″ maxlength=”30″>
<input type=”Submit” value=”Submit”>
</form>

Example 2: (Tip)

<input> input field Example 3:

<form method=post action=”/cgi-bin/example.cgi”>
<table border=”0″ cellspacing=”0″ cellpadding=”2″><tr><td bgcolor=”#8463ff”><input size=”10″ maxlength=”30″></td><td bgcolor=”#8463ff” valign=”Middle”> <input src=”yourimage.gif”></td></tr> </table>
</form>

Example 3: (Tip)

<input> input field Example 4:

<form method=post action=”/cgi-bin/example.cgi”>
Enter Your Comments:<br>
<textarea wrap=”virtual” rows=3 cols=20 maxlength=100></textarea><br>
<input type=”Submit” value=”Submit”>
<input type=”Reset” value=”Clear”>
</form>

Example 4: (Tip)

<input> input field Example 5:

<form method=post action=”/cgi-bin/example.cgi”>
<center>
Select an option:
<select>
<option >option 1</option>
<option selected>option 2</option>
<option>option 3</option>
<option>option 4</option>
<option>option 5</option>
<option>option 6</option>
</select><br>
<input type=”Submit” value=”Submit”></center>
</form>

Example 5: Tip)

Select an option:  option 1 option 2 option 3 option 4 option 5 option 6

<input> input field Example 6:

<form method=post action=”/cgi-bin/example.cgi”>
Select an option:<br>
<input type=”radio”> Option 1
<input type=”radio” checked> Option 2
<input type=”radio”> Option 3
<br>
<br>
Select an option:<br>
<input type=”checkbox”> Selection 1
<input type=”checkbox” checked> Selection 2
<input type=”checkbox”> Selection 3
<input type=”Submit” value=”Submit”>
</form>

Example 6: (Tip)

Select an option:
Option 1
Option 2
Option 3

Select an option:
Selection 1
Selection 2
Selection 3

<li> list item Example 1:

<menu>
<li type=”disc”>List item 1</li>
<li type=”circle”>List item 2</li>
<li type=”square”>List item 3</li>
</MENU>

Example 2:

<ol>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
<li>List item 4</li>
</ol>

Example 1: (Tip)

  • List item 1
  • List item 2
  • List item 3

Example 2:

  1. List item 1
  2. List item 2
  3. List item 3
  4. List item 4
<link> link <head>
<link rel=”stylesheet” href=”style.css” />
</head>
<marquee>
(Internet
Explorer)
scrolling text <marquee bgcolor=”#cccccc” loop=”-1″ scrollamount=”2″ width=”100%”>Example Marquee</marquee> Example Marquee(Tip)
<menu> menu <menu>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
</menu>
  • List item 1
  • List item 2
  • List item 3
<meta> meta <meta name=”Description” content=”Description of your site”>
<meta name=”keywords” content=”keywords describing your site”>
Nothing will show (Tip)
<meta> meta <meta HTTP-EQUIV=”Refresh” CONTENT=”4;URL=http://www.yourdomain.com/”> Nothing will show (Tip)
<meta> meta <meta http-equiv=”Pragma” content=”no-cache”> Nothing will show (Tip)
<meta> meta <meta name=”rating” content=”General”> Nothing will show (Tip)
<meta> meta <meta name=”robots” content=”all”> Nothing will show (Tip)
<meta> meta <meta name=”robots” content=”noindex,follow”> Nothing will show (Tip)
<ol> ordered list Numbered

<ol>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
<li>List item 4</li>
</ol>

Numbered Special Start

<ol start=”5″>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
<li>List item 4</li>
</ol>

Lowercase Letters<ol>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
<li>List item 4</li>
</ol>

Capital Letters

<ol>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
<li>List item 4</li>
</ol>

Capital Letters Special Start

<ol start=”3″>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
<li>List item 4</li>
</ol>

Lowercase Roman Numerals

<ol>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
<li>List item 4</li>
</ol>

Capital Roman Numerals

<ol>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
<li>List item 4</li>
</ol>

Capital Roman Numerals Special Start

<ol start=”7″>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
<li>List item 4</li>
</ol>

Numbered

  1. List item 1
  2. List item 2
  3. List item 3
  4. List item 4

Numbered Special Start

  1. List item 1
  2. List item 2
  3. List item 3
  4. List item 4

Lowercase Letters

  1. List item 1
  2. List item 2
  3. List item 3
  4. List item 4

Capital Letters

  1. List item 1
  2. List item 2
  3. List item 3
  4. List item 4

Capital Letters Special Start

  1. List item 1
  2. List item 2
  3. List item 3
  4. List item 4

Lowercase Roman Numerals

  1. List item 1
  2. List item 2
  3. List item 3
  4. List item 4

Capital Roman Numerals

  1. List item 1
  2. List item 2
  3. List item 3
  4. List item 4

Capital Roman Numerals Special Start

  1. List item 1
  2. List item 2
  3. List item 3
  4. List item 4
<option> listbox option <form method=post action=”/cgi-bin/example.cgi”>
<center>
Select an option:
<select>
<option>option 1</option>
<option selected>option 2</option>
<option>option 3</option>
<option>option 4</option>
<option>option 5</option>
<option>option 6</option>
</select><br>
</center>
</form>
Select an option: (Tip)
option 1 option 2 option 3 option 4 option 5 option 6
<p> paragraph This is an example displaying the use of the paragraph tag. <p> This will create a line break and a space between lines.

Attributes:

Example 1:<br>
<br>
<p align=”left”>
This is an example<br>
displaying the use<br>
of the paragraph tag.<br>
<br>
Example 2:<br>
<br>
<p align=”right”>
This is an example<br>
displaying the use<br>
of the paragraph tag.<br>
<br>
Example 3:<br>
<br>
<p align=”center”>
This is an example<br>
displaying the use<br>
of the paragraph tag.

This is an example displaying the use of the paragraph tag.

This will create a line break and a space between lines.

Attributes:

Example 1:

This is an example
displaying the use
of the paragraph tag.

Example 2:

This is an example
displaying the use
of the paragraph tag.

Example 3:

This is an example
displaying the use
of the paragraph tag.

<small> small (text) <small>Example</small> Example (Tip)
<strike> deleted text <strike>Example</strike> Example
<strong> strong emphasis <strong>Example</strong> Example
<table> table Example 1:

<table border=“4” cellpadding=”2″ cellspacing=”2″ width=”100%”>
<tr>
<td>Column 1</td>
<td>Column 2</td>
</tr>
</table>

Example 2: (Internet Explorer)

<table border=“2” bordercolor=”#336699” cellpadding=”2″ cellspacing=”2″ width=”100%”>
<tr>
<td>Column 1</td>
<td>Column 2</td>
</tr>
</table>

Example 3:

<table cellpadding=“2” cellspacing=”2″ width=”100%”>
<tr>
<td bgcolor=”#cccccc“>Column 1</td>
<td bgcolor=”#cccccc“>Column 2</td>
</tr>
<tr>
<td>Row 2</td>
<td>Row 2</td>
</tr>
</table>

Example 1: (Tip)

Column 1 Column 2

Example 2: (Tip)

Column 1 Column 2

Example 3: (Tip)

Column 1 Column 2
Row 2 Row 2
<td> table data <table border=”2″ cellpadding=”2″ cellspacing=”2″ width=”100%”>
<tr>
<td>Column 1</td>
<td>Column 2</td>

</tr>
</table>
Column 1 Column 2
<th> table header <div align=”center”>
<table>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>

</tr>
<tr>
<td>Row 2</td>
<td>Row 2</td>
<td>Row 2</td>
</tr>
<tr>
<td>Row 3</td>
<td>Row 3</td>
<td>Row 3</td>
</tr>
<tr>
<td>Row 4</td>
<td>Row 4</td>
<td>Row 4</td>
</tr>
</table>
</div>
Column 1 Column 2 Column 3
Row 2 Row 2 Row 2
Row 3 Row 3 Row 3
Row 4 Row 4 Row 4
<title> document title <title>Title of your HTML page</title> Title of your web page will be viewable in the title bar. (Tip)
<tr> table row <table border=”2″ cellpadding=”2″ cellspacing=”2″ width=”100%”>
<tr>
<td>Column 1</td>
<td>Column 2</td>
</tr>
</table>
Column 1 Column 2
<tt> teletype <tt>Example</tt> Example
<u> underline <u>Example</u> Example
<ul> unordered list Example 1:<br>
<br>
<ul>
<li>List item 1</li>
<li>List item 2</li>
</ul>
<br>
Example 2:<br>
<ul>
<li>List item 1</li>
<li>List item 2</li>
<ul>
<li>List item 3</li>
<li>List item 4</li>
</ul>
</ul>
Example 1:

  • List item 1
  • List item 2

Example 2:

  • List item 1
  • List item 2
    • List item 3
    • List item 4

The ProFTPD Server

The ProFTPD? Server

This page explains the FTP protocol, and then describes how to set up the ProFTPD? server and how to configure it for various purposes.

Introduction to FTP and ProFTPD?

FTP stands for file transfer protocol, and along with telnet and SMTP is one of the oldest protocols still in common use on the Internet. FTP is designed to allow client programs to read, write and delete files on a remote server, regardless of the operating system that the server is running. Essentially, it is a file sharing protocol, but unlike the more common NFS and SMB protocols, it is better suited to use over a slow or high latency network.

Typically, FTP is used to transfer files from one system to another. Sometimes those files are Linux distribution CD images or RPM packages, downloaded by various clients hosts on the Internet from a large server system that hosts them for everyone to access. Other times the files are pages for a web site, uploaded by an FTP client run by the sites owner to a system that runs both the web server and an FTP server.

Even though the FTP protocol has been mostly replaced by HTTP as a method of downloading files, it still has many advantages. The biggest is the ability of clients to upload files to the server, assuming that is has been configured to allow them. Another is a semi-standard directory listing format, which clients can use to fetch a list of files in a directory from the server.

When an FTP client connects to a server, it must first authenticate itself before any file transfers can take place. Often clients will login as the special anonymous user, which requires no password and is usually configured to be only able to download files. On Unix systems, most FTP servers allow any local user to login with the same username and password that he would use for telnet or SSH, and give his client access to the same files with the same permissions.

Another unique feature of the FTP protocol is its support for translating files between the data format used on the client and that used on the server. The most common use of this is the conversion of text files between the Unix, Windows and MacOS? formats, each of which uses different characters to represent the end of a line. This feature can be disabled for the transfer of binary files such as images, executables and ISOs, as it corrupts non-text data.

Many different FTP client programs exist, from the basic Unix ftp command to browsers like IE and Mozilla. Every modern operating system has at least one, and almost all include a client of some kind as standard. FTP servers are also plentiful, but this chapter focuses on only one – ProFTPD? , which in my opinion is the most flexible server available for Unix operating systems.

Even though all varieties of Unix ship with an FTP server as standard, the supplied server is usually either very basic and lacking in features, or the more powerful WU-FTPd. Although the latter has many configurable options, but is not as capable as ProFTPD? when it comes to virtual hosting, directory restrictions and locking users into their home directories.

ProFTPD? generally uses a single configuration file, found at /etc/proftpd.conf. This file is made up of directives, each of which usually occupies a single line and has a name and value. Each directive sets a single configurable option, such as the name of a hidden file or the path to a welcome message. There are also special container directives for grouping other directives that apply only to a single virtual server or directory, which span multiple lines.

The ProFTPD? Server Module

The ProFTPD? Server module icon can be found in Webmin under the Servers tab on the main menu. When you click on it, the module’s main page as shown in the image below will appear, assuming that you actually have the server installed.


The ProFTPD? Server module

If the main page instead displays an error message like *The ProFTPD? server /usr/sbin/proftpd could not be found on your system*, then the server is probably not installed and thus the module cannot be used. Most Linux distributions include a ProFTPD? package on their CD or website, so use the Software Packages module (covered in chapter 12) to install it. If no package exists, download the source code from http://www.proftpd.org, compile and install it.

If you already have some other FTP server installed, it should be removed first so that they do not clash.

Another error that the main page might display is *The program /usr/sbin/ftpd does not appear to be the ProFTPD? server*. This will occur if Webmin detects that some other FTP server is installed instead – if so, you will need to remove it and install ProFTPD? .

ProFTPD? can be run in two different modes – either as a stand-alone daemon process that listens for FTP connections, or from a super-server like inetd or xinetd. The former accepts connections faster, but at the cost of more memory being used up by a process that is running all the time. The latter is better for systems that do not expect to receive a lot of FTP traffic, as the ProFTPD? program only gets run when it is needed.

Because the stand-alone mode is easier to setup and because memory is plentiful on most systems, this chapter assumes that you will be running it in that mode. To start the ProFTPD? server process, follow these steps :

  1. In the Internet Services and Protocols module (covered on InternetServicesAndProtocols? ), make sure that any existing service named ftp hasProgram disabled or No program assigned selected. This ensures that no FTP service will be run by inetd. If you disable a service, make sure to hit the Apply Changes button on that module’s main page to activate your changes.
  2. In the Extended Internet Services module, make sure that any services with ftp in their names (such as wu-ftpd, proftpd, or vsftpd) have theirService enabled? field set to No. Again, you will need to hit the modules Apply Changes to activate any changes.
  3. Back in the ProFTPD? Server module, click on the Networking Options icon.
  4. Select Stand-alone daemon from the Server type menu.
  5. Click the Save button at the bottom of the page.
  6. Back on the module’s main page, a button labeled Start Server should appear at the bottom. Hit it to start the ProFTPD? daemon.
  7. If you want the daemon to be re-started at boot time, use the Bootup and Shutdown module to create an action called proftpd that runs the command /usr/sbin/proftpd at boot time. The actual path may be /usr/local/sbin/proftpd or /usr/sbin/in.proftpd depending on which Linux distribution you are running or if you compiled and installed the program yourself instead of using a package. Also, some ProFTPD? packages may include a bootup script like this already, which you may just have to enable.

Once ProFTPD? has been started, you can test it by using the command-line Unix FTP client to connect to your own system. Just run ftp localhost, and make sure that you can login as some user other than root. You can verify that the server really is ProFTPD? by checking the version displayed by the ftp command just before it prompts for a username, unless it has been configured by default not to display version information.

Running ProFTPD? from inetd or xinetd

Setting up ProFTPD? to run from a super-server isn’t too hard either, and may be a good idea if your system is low on memory or hardly ever receives FTP connections. Before you can do this, you must kill any existing proftpd server process (easily done with Running Processes module), and disable or delete any action that starts it at boot time.

If your system uses the superior xinetd, follow these instructions to set up the FTP service. Because many packages include an /etc/xinetd.d configuration file for the server, some of the fields explained below may be already filled in correctly.

  1. Go to Webmin’s Networking category and click on the Extended Internet Services icon. If it does not exist, xinetd is not installed and you will need to set up the server using inetd instead.
  2. On the module’s main page, check for an existing service named ftp or proftp. If one exists, click on it – otherwise, follow the Create a new internet service link above or below the table.
  3. In the Service name field, enter ftp (unless it has already been filled in).
  4. Make sure the Yes option is selected in the Service enabled? field.
  5. Leave the Bind to address field set to All, and the Port number to Standard or 21.
  6. Select Stream from the Socket type menu, and Default or TCP from the Protocol list.
  7. In the Service handled by field, select the Server program option and enter the path to the proftpd executable (such as /usr/sbin/proftpd) into the adjacent text box. The path depends on whether you installed the program from a package or compiled it from the source code.
  8. In the Run as user field, enter root.
  9. Select No for the Wait until complete? field.
  10. Leave all the other fields set to their defaults, and hit the Save or Create button at the bottom of the form.
  11. Back on the module’s main page, click the Apply Changes button below the list of services.

Alternately, to set up an inetd service for ProFTPD? using the Internet Services and Protocols module, follow these steps :

  1. Go to Webmin’s Networking category and click on the Internet Services and Protocols icon. If it does not exist, your system is probably using xinetd instead – see the steps in the previous paragraph for instructions on how to configure it.
  2. On the module’s main page, click on ftp in the Internet Services table. If it is not visible, enter ftp into the Edit service field and hit the button. Either way, the same page for editing the FTP protocol service will be displayed.
  3. In the Server Program section, select Program enabled.
  4. In the Program field, select the Command option and enter the full path to the ProFTPD? server executable into the field next to it, such as/usr/sbin/proftpd. In the Args field, enter just proftpd. The path depends on whether you installed the program from a package or compiled it from the source code.
  5. Set the Wait mode to Don’t wait, and enter root in the Execute as User field. All others can be left unchanged.
  6. Click the Save button, and then back on the module’s main page hit Apply Changes.

Once ProFTPD? has been setup to run from inetd or xinetd, you can test it by using the command-line Unix FTP client to connect to your own system. Just run ftp localhost, and make sure that you can login as some user other than root. If your test connection fails with an error like Service not available, the most likely cause is that ProFTPD? is configured to run as a stand-alone server. This can be easily fixed by following these steps :

  1. Go to the ProFTPD? Server module and click on the Networking Options icon on the main page.
  2. From the Server type menu in the form that appears, select Run from Inetd.
  3. Hit the Save button at the bottom of the page.

The instructions in the rest of this chapter will work fine no matter which mode ProFTPD? is running in. The only difference is that the Apply Changesbutton will not appear on the main page, as there is no need to re-start a server process for any configuration changes to take effect. Instead, changes will apply to the next FTP session that is started.

Using the ProFTPD? Server module

ProFTPD? uses a very similar configuration file format to Apache, and so the user interface for this module is the same in many ways as the Apache Configuration module. At the highest level in the configuration are global settings that effect the entire server. Below them are virtual servers, and then anonymous FTP options, per-directory options and options that apply only to certain FTP commands.

The options that apply to each connection or FTP command are determined by the virtual server connected to, the type of login, the directory the requested file is in and the specific FTP command used. Options set by objects lower in the hierarchy override those at upper levels, so that you can prevent uploading to a server, but allow it for a directory. Similarly, options for a more specific directory (like /usr/local/upload) override those for its parents (such as /usr/local).

A special case is the default server, which defines settings for clients that do not connect to any specific virtual server. Unlike Apache, options set in the default server do not effect virtual servers. Instead if you want to specify some setting that effects all of them it must be in the special global section of the ProFTPD? configuration. This applies to directory and FTP command specific options as well.

The module has a page for editing options for each object in the tree, which contains icons linking to objects further down. For example, on the virtual server options page are icons for the various categories of options that apply to that server (such as logging, and user and group), along with icons for any directories or FTP commands that have their own options within the virtual server. There is also an icon for options specific to anonymous FTP connections.

On each page in the hierarchy are forms for adding objects (such as a directory or group of FTP commands) under it, and a Configure icon for changing or deleting the current object. Every page also contains an Edit Directives icon allowing you to view and manually change the ProFTPD? directives for the directory, virtual server or whatever it is that the page represents. The exception is the default server page, which has no such icons because it cannot be changed or deleted and because its directives cannot be separated from the rest of the configuration file.

At first glance, some of the forms in the module may appear daunting as they display fields for almost all of the available ProFTPD? options in some category related to an object. However, many of these options are extremely specialized and can be ignore most of the time. The steps in the various sections of this chapter explain which ones your need to modify to achieve some result – the others can be left alone, as their defaults are usually adequate.

Because each new version of ProFTPD? that is released supports new directives, this module can detect the version that you are running and adjust its user interface to display only those fields that are valid for your version. This means that the forms may not look exactly the same on all systems, and that some parts of the instructions in this chapter may not be valid for your FTP server if your are running an older release.

Creating virtual servers

Probably ProFTPD? ‘s most useful feature is its support for virtual FTP servers. This allows you to define a totally different set of options that apply to clients connecting to a particular IP address. In most ways, they are similar to Apache’s IP-based virtual servers, which most website administrators should be familiar with.

Virtual servers are only really useful if your system has multiple IP addresses. Typically, this is done by adding additional virtual IP addresses to your Internet-connected network interface, as explained on the NetworkConfiguration page. As usual, any extra IP addresses must be properly routed to your system – if you are connected to an ISP and assigned only a single static address, you cannot just add additional virtual interfaces and expect them to work. Unlike Apache, ProFTPD? does not support name-based virtual servers because there is no provision in the FTP protocol for them. Clients never tell the server the hostname that they are connecting to, so the FTP server can only use the IP address that a connection was received on to determine which virtual server the client wants.

When your system receives an FTP connection, ProFTPD? will compare the connected address with those of all configured virtual servers. The first one to match defines the options that apply to the connection. If no match is found, the default server is used instead.

To add a new virtual FTP server to your system, the steps to follow are :

  1. In the Network Configuration module, add a new virtual IP address to the external network interface on your system. Make sure that it will be activated at boot time and is active now.
  2. Back in the ProFTPD? Server module, scroll down to the Create virtual server form at the bottom of the main page.
  3. In the Address field, enter the IP address that you just assigned. It should not be used by any other virtual server already defined.
  4. Leave the Port field set to Default.
  5. In the Server name field, select the second radio button and enter a name for this server that will be displayed to connecting clients. For example, you could enter Example Corporation’s FTP server. If Default is selected, clients will see a message like ProFTPD? 1.2.2rc2 Server instead.
  6. Hit the Create button to add the server. Once it has been created, you will be taken to the new server’s options page.
  7. Return to the module’s main page and click the Apply Changes button to make it active.

Once a virtual server has been created, you can set options that apply to it by clicking on its icon on the main page, then on one of the category icons. Some of these are explained in more detail later in the chapter. It is also possible to change the attributes of a virtual server by clicking on the Configure Virtual Server icon, editing the fields on the form (which have the same meanings as those on the creation form) and clicking Save. Or you can remove it altogether by hitting the Delete virtual server button on the configuration form.

Setting up anonymous FTP

In its default configuration, ProFTPD? will generally allow all Unix users to login with their normal passwords and access all files on the system with the same permissions that they would have if logged in via telnet or SSH. Some packages also have anonymous FTP enabled for the default server as well, so that anyone can connect as the anonymous user and view files in a specific directory. To set up anonymous FTP for a new virtual server, configure what clients can do and which directories they can access, follow these steps :

  1. On the module’s main page, click on the icon for the default or virtual server that you want to configure anonymous FTP for.
  2. On the virtual server options page, click on the Anonymous FTP icon. If this is the first time that it has been setup for this server, a small form will appear for entering anonymous FTP settings.
  3. In the Limit to directory field, enter the directory that anonymous clients should be restricted to, such as /home/example.com/anonftp.
  4. In the Access files as user option, select the second radio button and enter the name of an unprivileged Unix user such as ftp or nobody. Clients will not only be restricted to the chosen directory, but will also be only able to access files with the permissions of that Unix user. Naturally, you should make sure that it can actually read and list the directory and files that it contains. This user must not be in ProFTPD? ‘s denied list, or have an invalid shell. See the Limiting who can login section later in the chapter for more information on editing this list and allowing users with any shell.
  5. If you are happy for clients to use the group permissions of the user set in the previous field, leave the Access files as group field set to Default. Otherwise, select the second radio button and enter a group name into its field.
  6. Hit the Create button to set up the initial anonymous FTP configuration. Assuming it is successful, the browser will be re-directed to the anonymous FTP options page on which are icons for the various categories of configurable options that relate to anonymous FTP connections.
  7. Click on Authentication and in the Username aliases table enter anonymous under Login username, and the name of the user that you chose in step 4 under Real username. This tells ProFTPD? that clients logging in as anonymous should be given the permissions of that user.
  8. Click the Save button to return to the anonymous FTP options page.
  9. In the FTP commands field, enter WRITE and hit the Create button to start the process of defining options that apply to FTP commands that modify data on the server. You will be taken to the per-command options page.
  10. Click on the Access Control icon, and select Deny all clients in the Access control policy field. This tells ProFTPD? to block attempts by anonymous clients to upload, delete or rename files.
  11. Click the Save button.
  12. Return to the module’s main page, and hit Apply Changes. To make sure that everything is working, try logging into the virtual server as the anonymous user and downloading some files.

If you are using your system to host multiple web and FTP sites for different customers, each can be given his own virtual anonymous server to make files available to people via FTP. Browsers assume that ftp:// URLs require an anonymous login and most don’t deal well with FTP servers that require authentication.

Restricting users to their home directories

By default, clients that login to ProFTPD? as a valid Unix user (not anonymous) can browser your system’s entire filesystem, just as they could if the user logged in via SSH or telnet. However, this is not always desirable on a system that has multiple un-trusted users whom you want to prevent seeing each others files. Even though Unix permissions can be used to stop users listing each others’ directories, they cause problems if you are also running a webserver and need its httpd user to have access to everyone’s files.

Fortunately, ProFTPD? makes it easy to restrict users to their home directories or to some other directory. Because this only applies to FTP connections, it is pretty useless if those same users can telnet or SSH in. However, it is easy to allow a user to connect only via FTP by giving him a shell like /bin/false. On a virtual hosting server, users only really need to upload files for their websites and do not need Unix shell access at all. Just make sure that /bin/false or whatever non-functional shell that you choose is included in the /etc/shells file so that ProFTPD? does not deny the users access.

To restrict the directories that FTP clients can access, follow these steps :

  1. If you want to restriction to apply to only a single virtual server, click on its icon on the module’s main page and then on the Files and Directoriesicon on the virtual server options page. However, this is not advisable as it may allow users to avoid the restriction by connecting to another virtual server. Instead, you should just hit the Files and Directories icon in the Global Configuration section on the main page – any restrictions defined on it will apply to all servers. Either way, the page for configuring how the server lists directories and which ones are available (shown in the screenshot below) will appear.
  2. The Limit users to directories field is actually a table that allows you to enter one directory limitation at a time. It will always have one blank row, and if this is the first such restriction you have created that is all it will contain. In the Directory column, select Home directory to if that is where you want users to be restricted to. Alternately, you can select the third radio button and enter a path like /home or /var/www to confine users to that directory. It is also possible to enter a path relative to the users’ home directories, such as ~/public_html. In the Unix groups column, either select Everyone to have the restriction apply to all users, or select the second radio button and enter a group name to have it apply only to the members of that group. Multiple groups can be entered by separating their names with commas, like users,staff.
  3. Click the Save button to return to the virtual server options page. If you want to add another restriction (such as for a different group and directory), click on Files and Directories again and fill in the new blank row in the table.
  4. When done, return to the module’s main page and hit the Apply Changes button to make the restrictions active.


The files and directories form

From now on when restricted users connect, they will be unable to see files outside the specified directory or even work out which directory they have been limited to. Unlike some other FTP servers that support this kind of restriction, there is no need to copy any files or libraries like /bin/ls into the directory, as ProFTPD? does not depend on any external programs.

Limiting who can login

ProFTPD? does not allow every Unix user to login, even if they have valid usernames and passwords. The separate /etc/ftpusers file lists users who are not allowed to authenticate, which typically include system accounts such as bin, daemon and uucp. In addition, there is a separate configuration option that controls whether the root user is allowed to login or not. By default it is not, because passwords sent by the FTP protocol are not encrypted and thus allowing root to authenticate could be a major security risk.

ProFTPD? also by default prevents users without a valid shell from logging in. A valid shell is one listed in the /etc/shells file. This feature can be useful for preventing a large group of users from logging in, such as those that are supposed to be only able to connected to a POP3 server to download their email. However, it can be turned off if necessary.

To edit the list of denied users and other login restrictions, follow these steps :

  1. On the module’s main page, click on the Denied FTP Users icon. In the form that appears is a text box listing all blocked Unix users. Edit it to add or remove any that shouldn’t or should be allowed to login, and hit the Save button.
  2. To allow the root user to connect, click on the Authentication icon and change the Allow login by root? field to Yes.
  3. To allow users with unlisted shells to login, change the Only allow login by users with valid shell? field to Yes as well.
  4. Hit the Save button to return to the main page, then click Apply Changes to make the new restrictions active.

The options for allowing the root user and users with invalid shells to login can also be set on a per-virtual server basis as well, under the Authenticationicon on the virtual server options page. However, it is not generally useful from a security point of view to allow clients of just a single server to login, as users can choose any server to connect to.

Setting directory listing options

Normally, when an FTP client requests a directory listing ProFTPD? will return a complete accurate list in the format produced by the ls -l command. Sometimes though this gives away too much information about your system, such as the names of users and groups or symbolic link destinations. Often it can be useful to hide certain files that are not relevant to clients by must be kept in an FTP accessible directory for other reasons. This kind of information hiding is best applied to anonymous FTP users, as they should not be able to discover anything about your system that they do not need to know.

To change the format of directory listings, follow these steps :

  1. On the module’s main page, click on the icon for the default or virtual server that you want to change directory listings for to bring up its options page.
  2. Assuming that you want to only change the listed information for anonymous clients, click on the Anonymous FTP icon to go to the anonymous FTP options page. Otherwise normal Unix users will be effected as well.
  3. Click on the Files and Directories icon to bring up a form similar to the one in Figure 40-3 for setting the various listing options.
  4. To hide files with certain group owners, enter one or more group names separated by spaces into the Hide files owned by groups field. Be aware that files hidden in this way can still be downloaded, renamed or deleted unless Unix permissions or the server’s configuration prevents it.
  5. Similarly, to hide files with certain user ownership, fill in the Hide files owned by users field with a list of Unix usernames.
  6. To hide files that the anonymous FTP user would not be able to read, change the Hide files that cannot be accessed? field to Yes.
  7. To have ProFTPD? convert symbolic links in listings to their target file permissions and size, change the Show symbolic links? field to Yes. Normally both the link and target name are shown, and the displayed permissions and ownership are those of the link. However, even with this feature enabled the link target must still be within the anonymous FTP directory.
  8. Normally, directory listings include the real user and group owners of files. To change this, set the Fake group in directory listings? field to Yes, as group. Then from the box below select either ftp to force the group owner to be always shown as ftp, or the third radio button to have it shown as whatever group you entered into the adjacent text box. The Connected group option only really makes sense for non-anonymous clients, as it makes files appear to be owned by the primary group of the connected user.
  9. Similarly, you can change the Unix user owner of files with the Fake user in directory listings? field. If Connected user is chosen, files will appear to be owned by the user currently logged into the FTP server.
  10. By default, ProFTPD? will show real Unix file permissions in listings. To force the display of fakes instead, select the second option in the Fake permissions in directory listings field and enter an octal number like 0644 of the kind used by the chmod command. This has no effect on the actual permissions that apply if a client tries to download or upload a file of course.
  11. To hide dot files like .login and .profile in listings (as the ls command usually does), set the Show files starting with . in listings? field to Yes.
  12. Finally, hit the Save button at the bottom of the page to update the ProFTPD? configuration file.
  13. Return to the module’s main page and press the Apply Changes button to make the settings active.

As well as hiding certain files (as explained in steps 4 and 5), you can also prevent clients from reading or writing those files altogether. This can be done using the Make hidden files inaccessible? field, explained in the Restricting access to FTP commands section later in the chapter.

Message and readme files

ProFTPD? can be configured to display messages to clients when they login or enter certain directories. This can be useful for notifying users of possible mirror sites, the locations of various common files on the server, and the details of the contents of a directory.

To set the messages that are displayed to clients, follow these steps :

  1. If you want the messages to be used by all virtual servers, click on the Authentication icon on the module’s main page. To set messages for a specific virtual server, click on its icon and then on Authentication on the server options page. Either way, the same form will be displayed. It is also possible to set most of the message file options below for only anonymous clients by clicking on the Anonymous FTP icon on the virtual server page and then on Authentication. Naturally, you cannot set the pre-login message because the server does not know if a client is anonymous or not at that stage.
  2. In the Pre-login message file field, enter the full path to a file whose contents should be sent to clients as soon as they connect. If you don’t want any message file to be used at all, select None instead.
  3. In the Post-login message file field, enter the path to a text file whose contents will be sent to clients after they have been properly authenticated. If the client is limited to a directory (because it logged in anonymously or has a home directory restriction in force), the file must be within and relative to that directory. If the filename is relative (like welcome.txt), it will be searched for in the directory that the client is initially placed in.
  4. To set a message sent to clients when they request to disconnect, fill in the Logout message file field. Again, this must be relative to and under any directory that the client is restricted to.
  5. If you have a restriction on the maximum number of simultaneous logins in force, you can set the message sent to clients blocked by it by filling in the Too many connections message file field. You should enter a full path, which can be anywhere on your system. See the Limiting concurrent logins section for more details.
  6. Hit the Save button at the bottom of the page to go back to the global, virtual server or anonymous FTP options page.
  7. Click on the Files and Directories icon on the same page.
  8. In the Directory README filename field, enter a relative name like readme.txt that will be searched for in each directory that a client enters. If this is the first time the client has entered the directory in this session (or if the file has changed since the last time), its contents will be sent to the FTP client.
  9. To have the server send a message to clients suggesting that a particular file should be read, fill in the Notify user of readme files matchingfield. If files in the directory matching the specified regular expression (like README.*) exist, a short message containing their names and modification times will be sent.
  10. Click the Save button on this form, then return to the module’s main page. Finally click the Apply Changes button to activate the new message file settings.

The files sent to the client by the options covered above can contain certain special cookies that start with a %, which are replaced by ProFTPD? with text determined at the time of sending. According to the ProFTPD? documentation, the currently supported cookies are :

Not all may make sense in all situations though – for example, %U will not be set in the pre-login message file.

Setting per-directory options

The ProFTPD? module allows you to set options that apply only to a specific directory, rather than globally or to an entire virtual server. This allows you to do things like hide a directory from clients, allow uploads by anonymous clients in just one location, or set the user and group ownership of files added to a directory.

To create a new set of per-directory options, follow these steps :

  1. If you want the options to apply to all virtual servers, enter the directory into the Directory path field in the Add per-directory options for form on the module’s main page and hit the Create button. Alternately, you can limit them to a particular virtual server by clicking on its icon and using the same form on the virtual server options page. Or you can define options that only apply to anonymous clients by hitting the Anonymous FTP icon for a virtual server and using its directory options creation form. In all cases, the directory should be entered as an absolute path like /usr/local. It is also possible to specify a path relative to the connecting user’s home directory, like ~/public_html. You can even enter a path in a particular user’s home directory, like ~jcameron/www. Normally, the options will apply to the directory and all its contents and subdirectories. To have them apply to only the contents and not the directory itself, add /* to the end of the path that you enter, like /usr/local/*.
  2. After hitting Create, you will be taken to a page of option category icons for the directory as shown in Figure 40-4. As usual, clicking on these icons will take you to forms for configuring various settings that apply only to requests for and listings of that directory.
  3. To totally deny access to clients, click on Access Control and change the Access control policy field to Deny all clients, then click Save.
  4. Normally, files uploaded by clients will end up owned by the Unix user that the client logged in as. To change this, click on the User and Groupicon and enter a username for the Owner of uploaded files field. Uploaded files’ group will be the primary group of the specified user, unless you fill in the Group owner of uploaded files field as well. Again, click Save after making any changes to return to the per-directory options page.
  5. To limit only the uploading or downloading of files in this directory, you will need to create a set of per-command options under it. The Restricting access to FTP commands section explains how.
  6. To activate your changes for this directory, return to the module’s main page and hit the Apply Changes button.


The per-directory options page

You can also remove a directory options object from the ProFTPD? configuration entirely by clicking on Configure Directory and then hitting the Delete directory config button. All settings and per-command options for the directory will be immediately and permanently deleted from the FTP server’s configuration.

If you define options for both a directory and one of its children (such as /usr/local and /usr/local/bin), ProFTPD? will always give precedence to the most specific directory when deciding which options to apply to a particular client request. This means that a setting made for /usr/local will apply to a download of /usr/local/bin/foo, unless it is overridden by a setting for /usr/local/bin.

Restricting access to FTP commands

When a client wants to download or upload a file, list a directory or perform any other operation it sends a command to the server. ProFTPD? can be configured to restrict which commands a client can use for a particular virtual server or directory, or when logged in anonymously. However, before you can do this you need to have a basic understanding of which FTP commands exist and what they do. The table below lists the ones that are relevant for access control purposes :

ProFTPD? allows you to define options that only apply to particular client commands or groups of commands. Typically, this is used to deny access to certain operations, such as uploading by anonymous FTP users. It is also possible to allow or deny only certain Unix users, or only clients connecting from certain addresses.

To create a new set of per-command options, follow these steps :

  1. First decide if the options should apply to commands only in a particular directory, only to clients of a virtual server, only to anonymous clients or to all users of your FTP server. On the per-directory, virtual server, anonymous FTP and main pages is a form titled Add per-command options for. In the FTP commands field, enter one or more commands from the list above, separated by spaces. When you hit the Create button, your browser will be taken to the page shown in Figure
  2. -5.
  3. Click on the Access Control icon to bring up a form for restricting who can use these commands.
  4. To completely deny access to everyone, change the Access control policy field to Deny all clients. Conversely, to allow access select Allow all clients instead. This is most useful if you are editing options for commands within a directory and there is a set of options for the same commands at a higher level (such as for the virtual server or anonymous FTP) that denies access. For example, typically anonymous clients cannot use the WRITE commands, but you may want to allow it for a particular directory.
  5. To only allow certain Unix users or members of certain group access to the commands, fill in the Only allow users and Only allow group fields. Multiple user or group names must be entered separated by spaces.
  6. Similarly, to deny certain users and groups while allowing everyone else access to the FTP commands, fill in the Deny users and Deny groupsfields.
  7. The Restrict access table can be used to block clients from certain IP addresses by entering a series of rules. The three radio buttons at the top control the order in which entries in the table are evaluated. If Deny then allow is selected, any client that matches a Deny row or which does not match an Allow row will be blocked. Conversely, if Allow then deny is chosen only clients that match a Deny row and do not match an Allow will be prevented from using the commands. This mode is also the default. The table will always have one empty row for adding a new rule, and because this is a new set of per-commands options that is all it will contain. In the empty row select either Allow or Deny from the Action menu. Then from the Condition menu choose one of the following to determine which clients match and thus are allowed or denied. All *All clients match, no matter where they are from. *None *No clients match the rule. *IP address *Only clients from the IP address entered in the adjacent text field match. *Network *Only clients from the IP network entered match. The network address must be a partial IP with a trailing dot, like 192.168.1.. *Hostname *Only clients whose IP address reverse-resolves to the entered name match. You can specify an entire domain by putting a dot at the front, like .example.com. If you want to add more than one rule, you will need to re-enter this page after saving so that a new blank row appears. To delete a rule, select the blank option from the *Action menu.
  8. When you are done choosing who can use the FTP commands, hit the Save button. Then return to the module’s main page and click Apply Changes to make the restrictions active.


The per-command options page

Configuring logging

By default, ProFTPD? logs all transfers to the file /var/log/xferlog in the standard FTP logging format (unless a different path has been selected at compile time). However, you can configure the server to log transfers to and from each virtual server differently, and anonymous FTP traffic as well. This is most useful in a virtual hosting environment, in which your system hosts FTP sites for many different customers.

It is also possible to define additional log files that use different formats, and optionally include only a subset of FTP commands. This can be useful if you only care about uploads, and don’t want your log files clogged up with useless information.

To configure where and how logs are written globally or for an individual virtual server, the steps to follow are :

  1. If you want to change the location of the global log file that is used for all transfers (unless overridden by a virtual server), click on the Loggingicon on the main page. Alternately, if you want to configure a specific virtual server to use a different log file, click on its icon and then on Loggingon the virtual server options page. To change the logging settings for anonymous clients only, click on a virtual server icon, then on Anonymous FTP and finally on the Logging icon on the anonymous FTP options page.
  2. On the resulting logging options form, the FTP transfers logfile field controls where logs are written to. To specify a file, select the last option and enter a full path like /var/log/example.com.xfers into the adjacent text field. To turn off logging altogether, select Logging disabled. To use the global default, select the Default option (if you are editing the global logging settings, ProFTPD? will use the compiled-in default log file /var/log/xferlog).
  3. The Custom logfiles table can be used to define additional logs for specific commands and with arbitrary formats. As usual, it will always have one empty row for adding a new custom log file. To add one, fill in the fields under these headings : Logfile *The full path to the log file, such as/home/example.com/ftplog. *For FTP commands *If *All is selected, all FTP commands will be logged. However, if you choose the second option only those command classes in the adjacent text box will be included. Recognized classes are NONE (no commands), ALL (all commands), INFO (information requests), DIRS (directory navigation), READ (file download), WRITE (file upload and directory creation), SITE (non-standard commands like CHMOD) and MISC (other miscellaneous commands). Multiple classes must be separated by commas, like READ,WRITE. You cannot use the names documented in the Restricting access to FTP commands section. Log format *If *Default is selected, the standard FTP log format will be used. But if the second option is chosen, you must enter a recognized log format name into the text box. The next paragraph explains how to set up named log formats. Because only one empty row appears in the table, you can only add one custom log at a time. To add more, click on the Logging icon again after saving and fill in the new blank row. To delete a custom log, just clear out its field in the Logfilecolumn.
  4. Hit the Save button to save the new settings, and then Apply Changes on the main page to activate them.

If you want to use your own custom formats for log files, they must first be defined globally. The steps to create a format are :

  1. On the module’s main page, click on the Logging icon to bring up the global log file options page.
  2. The Custom log formats table is for defining your own formats. In the first blank field under Format name, enter a short name for your new format such as filesonly. In the field next to it under Format string, enter text containing the log codes recognized by ProFTPD? , like Downloaded %f at %t. The special codes in the string starting with % are replaced by the server with information about the command, as explained in the table below. As usual, you can add more than one custom format by re-entering the page after saving so that a new blank row appears. A format can be deleted by just clearing out its Format name field.
  3. Click the Save button to return to the main page, and then click Apply Changes. The new format can now be used in custom log files.

Limiting concurrent logins

If your system is configured to allow anonymous FTP logins and you expect to receive a lot of traffic, it makes sense to limit the number of connections that can be open to the FTP server at any one time. This puts a ceiling on the network and CPU load that FTP transfers can generate, which is important if the system is being used for some other purpose (such as running a web server).

This limit can be set globally, on a per-virtual server basis or just for anonymous clients. This means that you can set a limit that applies to all servers, and then increase or decrease it for a particular virtual host. Or you can set a lower limit for anonymous clients versus those that have valid logins.

ProFTPD? can also be configured to limit the number of concurrent connections that a single client host can have. This is useful if you want to stop people downloading more than one file at a time from your server, and thus taking more than their fair share of bandwidth.

To set a connection limit for your server, follow these steps :

  1. If you want to set a global limit, click on the Networking Options icon on the module’s main page. To set a limit for a single virtual server, click on its icon and then on Networking Options. To define a limit that applies only to anonymous clients, click on the icon for a virtual server, then onAnonymous FTP and finally on the Networking Options icon on the anonymous FTP options page.
  2. On the form that appears, find the Maximum concurrent logins field. To set a limit, select the third radio button and enter a number in the text box next to it. Alternately, you can select Unlimited to turn off any restriction that applies to this virtual server that has been set globally.
  3. To define an error message sent to clients that try to connect when the limit has been reached, enter it into the Login error message box in theMaximum concurrent logins field. If the message contains the special code %m it will be replaced with the maximum allowed number.
  4. To set the per-client host limit, fill in the Maximum concurrent logins per host field in the same way. It also has a Login error message box that can be used to set a message sent to FTP clients that exceed the limit.
  5. If you are editing the global networking options, you can also set a limit on the total number of ProFTPD? sub-processes that can be active at any one time. This is useful for protecting your system from denial-of-service using hundreds of useless connections. Just select the second option for the Maximum concurrent sessions field and enter a number into its adjacent text box. If Default is selected, no limit will be enforced. If you are running the server from a super-server like inetd or xinetd, this limit will have no effect. Fortunately, both those servers have configuration options that can be used to achieve the same result.
  6. When you are done editing client restrictions, hit the Save *button at the bottom of the form to update the ProFTPD? configuration, and then the *Apply Changes button back on the main page.

Restricting clients by IP address

By default, ProFTPD? will allow clients to connect from any IP address. However, like everything else this is configurable so that you can restrict access to systems on your own network, either globally or for particular virtual servers. This comes in handy if you are setting up an FTP server that is for internal use only, even though the system it is running on is accessible from the Internet.

To restrict clients by address, follow these steps :

  1. To create a global restriction that will apply to all virtual servers, enter LOGIN into the FTP commands field of the Add per-command options for form on the module’s main page, then click Create. If you only want to limit who can connect to a particular virtual server, click on its icon before entering LOGIN into the same form on the virtual server options page.
  2. Regardless of what level the restriction is being defined at, you will be taken to the per-command options page shown above. Click on the Access Control icon to go to the aptly-named access control form.
  3. The Restrict access table can be used to block clients from certain IP addresses by entering a series of rules. The three radio buttons at the top control the order in which entries in the table are evaluated. If Deny then allow is selected, any client that matches a Deny row or which does not match an Allow row will be blocked. Conversely, if Allow then deny is chosen only clients that match a Deny row and do not match an Allow will be prevented from logging in. This mode is also the default. The table will always have one empty row for adding a new rule, and because this is a new set of per-commands options that is all it will initially contain. In the empty row select either Allow or Deny from the Action menu. Then from the Condition menu choose one of the following to determine which clients match and thus are allowed or denied.
    • All All clients match, no matter where they are from. *None *No clients match the rule.
    • IP address Only clients from the IP address entered in the adjacent text field match.
    • Network Only clients from the IP network entered match. The network address must be a partial IP with a trailing dot, like 192.168.1..
    • Hostname Only clients whose IP address reverse-resolves to the entered name match. You can specify an entire domain by putting a dot at the front, like .example.com. If you want to add more than one rule, you will need to re-enter this page after saving so that a new blank row appears. To delete a rule, select the blank option from the Action menu.
  4. When you are finished entering client restrictions, hit the Save button at the bottom of the form. Then return to the main page and click Save and Apply to activate them.

Commonly, you will want to give only clients on a single network access. To do this, select the Deny then allow option, choose Allow from the Action menu, Network from the Condition menu and enter the network address with a trailing dot (like 10.254.1.) into the condition text box.

Limiting uploads

If clients are allowed to upload files to your server, they will be able to choose any name that they wish for uploaded files. Sometimes this is not desirable though – you may want to allow the storing of only image files whose names end with .gif or .jpg, or prevent the uploading of Windows executables with filenames ending in .exe or .com. Fortunately, ProFTPD? has configuration options that allow you to set this up.

There are also several other settings that apply to uploads, which control whether clients are allowed to overwrite files and if partially transferred files are visible. All can be set globally, for a single virtual server or for anonymous clients only. The steps to set these options are :

  1. If you want to the settings to be global, click on the Files and Directories icon on the module’s main page. To have them apply to just a single virtual server, click on its icon and then on Files and Directories. Or to effect just clients that login anonymously, click on a virtual server icon, then on Anonymous FTP and finally on Files and Directories icon on the virtual server options page. No matter which configuration object you chose, the files and directories form that appears will be almost identical.
  2. To hide files that are in the process of being uploaded, change the Hide files during upload? field to Yes. This tells ProFTPD? to use a temporary file whose name starts with .in. for transferred data, which is only renamed to the real filename when the upload is complete. This prevents incomplete partial uploads, and stops files being downloaded or accessed while they are still being sent.
  3. To have ProFTPD? delete uploaded files that are not fully transferred, select Yes for the Delete aborted uploads? field. Again, this prevents corrupt partially uploaded files from being created on your system.
  4. To allow users to only create files whose relative names match a certain pattern, fill in the Allowed uploaded filename regex field with a Perl regular expression. For example, to only allow GIF files you might enter ^.*\.gif$. Because clients are normally allowed to rename files, this option alone is not enough to stop the creation of invalid filenames. You will also need to block access to the RNFR command, as explained in theRestricting access to FTP commands section.
  5. Alternately, you can block the use of certain filenames by filling in the Denied uploaded filename regex field with a regular expression like^.*\.exe$. If both this and the previous field are set, only files that match the allow expression but not this deny expression will be permitted. Another common use of this option is blocking the upload of .ftpaccess or .htaccess files, which set per-directory ProFTPD? and Apache options.
  6. Hit the Save button at the bottom of the page.
  7. If you want to stop clients overwriting files with new uploads, click on the Access Control icon and change the Allow overwriting of files? field toNo. This can be useful on an server that allows anonymous users to upload to a particular directory, perhaps for incoming files of some kind. Don’t forget to click Save if you make this change.
  8. Return to the module’s main page and hit the Apply Changes button to activate your new filename restrictions.

Manually editing directives

If you prefer to manually edit your ProFTPD? configuration file in some cases or just want to see which directives an action in Webmin has set, you can do so using this module. Except for the default server, every object’s options page (virtual server, per-directory and per-command) has an icon labeledEdit Directives. When clicked on it will take you to a form containing a large text box showing the lines from the configuration file in the section related to the object. You can edit them to your heart’s content, then click the Save button to update the actual file. Be aware though that no validation of your input is done. Also, you will need to use the Apply Changes button on the module’s main page to activate any changes, as usual.

To view and edit the entire ProFTPD? configuration, use the *Edit Config Files* icon on the module’s main page. This will bring up a similar form, but showing and allowing the editing of a complete configuration file at once. Because ProFTPD? can read multiple configuration files (though the use of Include directives), at the top of the form is a button labeled Edit Directives in File with a menu of filenames next to it. To switch the view to a different file, just select the one you want and hit the button. Normally though only a single proftpd.conf file will be used.

PHP MySQL: Creating Form Insert Data

01 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
02 Transitional//EN"
03 "http://www.w3.org/TR/html4/loose.dtd">
04 <html>
05
06 <head>
07 <title>Form Input Data</title>
08 </head>
09
10 <body>
11 <table border="1">
12 <tr>
13 <td align="center">Form Input Employees Data</td>
14 </tr>
15 <tr>
16 <td>
17 <table>
18 <form method="post" action="input.php">
19 <tr>
20 <td>Name</td>
21 <td><input type="text" name="name" size="20">
22 </td>
23 </tr>
24 <tr>
25 <td>Address</td>
26 <td><input type="text" name="address" size="40">
27 </td>
28 </tr>
29 <tr>
30 <td></td>
31 <td align="right"><input type="submit"
32 name="submit" value="Sent"></td>
33 </tr>
34 </table>
35 </td>
36 </tr>
37 </table>
38 </body>
39 </html>

The result:

php mysql form input data

This HTML form will send two variable, $name and $address variable, into input.php file as describe in the ACTION parameter of FORM HTML.

01 <?
02 //the example of inserting data with variable from HTML form
03 //input.php
04 mysql_connect("localhost","root","admin");//database connection
05 mysql_select_db("employees");
06
07 //inserting data order
08 $order = "INSERT INTO data_employees
09 (name, address)
10 VALUES
11 ('$_POST[name]',
12 '$_POST[address]')";
13
14 //declare in the order variable
15 $result = mysql_query($order); //order executes
16 if($result){
17 echo("<br>Input data is succeed");
18 } else{
19 echo("<br>Input data is fail");
20 }
21 ?>

After you have already made input.php, fill the input data and then click the sent button such as:

PHP mysql basic insert data

For the result:

PHP mysql basic insert data

Postfix with LDAP

Postfix’s LDAP Suppport

Postfix stores aliases, virtual address mappings and other configuration tables in maps, which are typically DBM format files built from text files. However, with the right plugin modules it can use a MySQL or LDAP database instead, which can be queried over the network.

On Debian or Ubuntu systems, the command to install LDAP support for Postfix is :

apt-get install postfix-ldap

On other systems, Postfix may come with LDAP support already enabled. If not, you may need to download and compile it manually. To check if your Postfix supports LDAP, run the command :

postconf -m

and look for ldap in the output.

Setting up the LDAP Schema

I’ve found that there doesn’t seem to be any consistent agreement on which LDAP object class and attributes to use for Postfix objects. However, the misc schema that comes with OpenLDAP defines ainetLocalMailRecipient class that is almost good enough.

To configure the schema fully, do the following :

  1. Go to the LDAP Server module, and click on Manage Schema.
  2. Check the box next to the misc schema (if it isn’t already), and click Save.
  3. Go back to the schema page, and click the Edit link next to the misc schema.
  4. Find the definition for the inetLocalMailRecipient class, which should be like :
    objectclass ( 2.16.840.1.113730.3.2.147
    	NAME 'inetLocalMailRecipient'
    	DESC 'Internet local mail recipient'
    	SUP top AUXILIARY
    	MAY	( mailLocalAddress $ mailHost $ mailRoutingAddress ) )
  5. Change the AUXILIARY to STRUCTURAL, and click Save.
  6. Go back to the module’s main page, and click Apply Configuration.

Creating LDAP Trees for Postfix

Each Postfix map should have a separate sub-tree in the LDAP database.

  1. Click on Create Tree.
  2. Select Distinguished name, and in the adjacent field enter something like dc=Users,dc=foo,dc=com or dc=Mail,dc=foo,dc=com
  3. Click Create.

Configuring the Webmin Postfix Module

Now that the LDAP server is set, Postfix has to be told to talk to it. The first step is to have it use the correct LDAP object class, by doing :

  1. Go to the Postfix Mail Server module, and click on Module Config.
  2. Find the LDAP options section.
  3. Change the Object classes for maps to inetLocalMailRecipient .
  4. Change the Key attribute for map objects to mailLocalAddress .
  5. For Create separate DN for each domain?, select No .
  6. Click Save.

Now you need to edit the maps for aliases and virtual domains to add LDAP data sources, as follows :

  1. Go to the Postfix Mail Server module, and click on Mail Aliases.
  2. Click the … button next to Alias databases used by the local delivery agent. By default, this field will just contain something like hash:/etc/aliases.
  3. In the popup window, scroll down to the Map source 2 section and select LDAP server.
  4. Enter your LDAP server’s hostname in the LDAP server hosts field.
  5. Set the LDAP search base DN to the DN you created previously, such as dc=Users,dc=foo,dc=com, or dc=Mail,dc=foo,dc=com .
  6. Set the Query filter to mailLocalAddress=%s .
  7. Set the Result attribute to mailRoutingAddress .
  8. In the Server login field, enter your LDAP server’s administration login, like cn=Admin,dc=foo,dc=com .
  9. Enter the LDAP administration password in the Server password field.
  10. Click Save at the bottom of the popup window.
  11. Click Save again back on the Mail Aliases page.

It is also possible to use a different login, such as an LDAP account who just has read-write access to the aliases sub-tree.

To verify that everything is working, try adding an alias using Webmin and ensure that it shows up in the list of aliases. Then send email to the new alias, and check that it is forwarded correctly. If not, check the Postfix logs in /var/log/mail* for errors that explain why it couldn’t talk to the LDAP database.

LDAP with Webmin

Combining Virtualmin and LDAP

This documentation explains how Virtualmin can be setup to store users and mail aliases in an LDAP database, rather than using files in /etc as it does by default. It is particularly useful when you want to spread the load of virtual hosting across multiple systems, and need to them to all stay in sync.

Introduction to LDAP

LDAP (Lightweight Directory Access Protocol) is a way for clients to query and update a flexibly structured heirachial database. In the Unix world, it is most commonly used to distribute user and group information from a central server to many client systems, so that users can login to any client. Typically it is combined with NFS, which makes user home directories available on all clients too.

Each object in the database has a DN (distinguished name), which is formatted like:

cn=joe,dc=example,dc=com

As you can see, the DN is split into components, each of which is one element of the heirarchy. Most DNs are based on an internet domain name, although it is possible to use an organization’s structure instead.

Each object in an LDAP database has one or more object classes. These determine what type of user it is, such as posixAccount for a Unix user, or posixGroup for a group. Users who have additional shadow password information will have the class shadowAccount too.

Each object has a list of attributes, each of which has a name and value. Typical attributes for Unix users are uid for the username, homeDirectory, loginShell and userPassword. The attributes allowed for each object differ depending on the object’s classes.

LDAP Access Control

When a client connects to an LDAP server, it can either authenticate itself with a DN and password, or connect anonymously. The server’s configuration determines which are allowed, and which objects and attributes a client is allowed to read or write based on this DN.

The popular OpenLDAP server has a special root DN which has read/write access to everything in the database. This DN does not even have to exist in the database, as it is defined in the server’s configuration file.

Installing an LDAP Server

An LDAP server is responsible for managing the data files that make up an LDAP database, and providing access to that data to clients via the network. The most popular free LDAP server is OpenLDAP (http://www.openldap.org/), which is available for pretty much all Unix-like operating systems.

If you are running a CentOS, Fedora or Redhat Enterprise system, OpenLDAP can be installed with the command :

yum install openldap openldap-servers openldap-devel openldap-clients perl-LDAP

On CentOS, Fedora and Redhat Enterprise systems, the built-in LDAP server configuration will be used by default, which is not optimal for high-performance environments. To use a better configuration, run these commands :

cp /etc/openldap/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
/etc/init.d/ldap start

On an Ubuntu or Debian system, the command to use is :

apt-get install slapd php-net-ldap

On other operating systems, you will probably have to download, compile and install OpenLDAP manually. You should also install the Net::LDAP Perl module, which Webmin and Virtualmin need to talk to the server.

Setting up Webmin’s LDAP Server Module

This module allows you to configure an OpenLDAP server, manage objects in its database, and setup access control for objects. It can be found in Webmin under the Servers category. By default, it should be configured automatically to find the OpenLDAP package provided by the your Linux distribution vendor.

Before the LDAP server can be used to store users and groups, a few configuration steps must be performed. These can be skipped if you have already manually setup the server.

  1. Click on the OpenLDAP Server Configuration icon.
  2. In the Root DN for LDAP database field, enter a base DN for your LDAP database. This is typically based on your domain name, so for a domain like foo.com you would enter dc=foo,dc=com .
  3. In the Administration login DN field, enter a DN like cn=Manager,dc=foo,dc=com .
  4. In the New administration password field, select Set to and enter a new password of your choice.
  5. Click Save.
  6. Open the Manage Schema page, and make sure the nis schema is checked.
  7. If not, check it and click Save.
  8. Back on the main page, click Apply Configuration or Start Server.
  9. If Webmin prompts you to create the root DN you just specified, click the button to do so.

Verify that the server is running and serving your base DN by clicking on the Browse Database icon. You should see the attributes of your new base object, which will have a class like domain.

Since we want the LDAP server to remain running from now on, on the module’s main page select Yes next to the Start at boot button, and click it. This will enable the /etc/init.d script provided by your Linux distribution.

Creating LDAP Trees

Now you have a root DN, you will want to create another DN under it to contain your LDAP users. This can be considered like a sub-directory, and even though you could create all objects under one DN, it isn’t particularly neat and will slow down database searches.

To create a new DN for users, do the following :

  1. Click on the Create Tree icon.
  2. Select Distinguished name, and in the adjacent text field enter something likedc=Users,dc=foo,dc=com .
  3. Change Create example object under new DN? to Unix user.
  4. Click Create.

If all goes well, the Users DN will be created, and an example Unix user object created under it. You can see them by navigating around on the Browse Database page.

You should then repeat the same steps to create a sub-tree for LDAP groups :

  1. Click on the Create Tree icon.
  2. Select Distinguished name, and in the adjacent text field enter something likedc=Groups,dc=foo,dc=com .
  3. Leave Create example object under new DN? set to No.
  4. Click Create.

Storing Users in LDAP

Most Unix-like operating systems (including Linux) can query an LDAP database for user and group information, which is then used by all programs and servers on the system. This means that LDAP users can login via SSH and FTP, own files, run processes and do everything that a user in /etc/passwd can do.

Introduction to NSS

On Linux, NSS (Name Service Switch) is the library that determines where user and group information comes from. On a typical system only the /etc/passwd and /etc/group files were used, but because NSS is extensible it is possible to add support for any type of data source. Another that is often used is NIS, which has a similar client-server architecture to LDAP, but is losing popularity in favour of LDAP.

Before your system can fetch users from an LDAP database, the NSS module for it must be installed. On a CentOS, Fedora or Redhat system the command to do this is :

yum install nss_ldap

While on Debian or Ubuntu Linux, the command to use is :

apt-get install libnss-ldap

When run from the command line, this may ask several questions about the hostname of the LDAP server, the root DN and administration login. You should be able to answer them all based on the LDAP server setup done above.

Introduction to PAM

PAM is a set of libraries and configuration files similar to NSS, but it deals only with passwords. It was designed to make the implementation of alternate authentication types (like RSA tokens or networked user databases) easier. Because you want users in the LDAP database to be able to login, you will need to install the a PAM module for it.

On Debian or Ubuntu Linux, the command to install is :

apt-get install libpam-ldap

When run from the command line, this may ask several questions about the LDAP root DN and administration login. The answers should be the same as what you gave to the libnss-ldap package.

For reasons unknown to me, Debian and Ubuntu systems have two separate configuration files for LDAP integration, one for NSS and one for PAM – even though they really should contain the same information. To reduce your system to using just one, run the commands :

mv /etc/pam_ldap.conf /etc/pam_ldap.conf.old
ln -s /etc/libnss-ldap.conf /etc/pam_ldap.conf

On CentOS, Fedora or Redhat systems the needed PAM libraries are part of the nss_ldap package that you should have already installed in the previous step.

Setting Up an LDAP Client System

By now, you should have an LDAP database running with an example user in it. Your system has to be configured to actually use this database, which is best done using Webmin’s LDAP Client module (found under the System category).

First, your system has to be told which LDAP server to use. To do this :

  1. Click on the LDAP Server Configuration icon.
  2. In the first row of the LDAP servers table, enter your system’s hostname or localhost in theHostname field.
  3. In the Login for root user field, enter the full administrator’s DN, like cn=Manager,dc=foo,dc=com .
  4. In the Password for root user field, enter the password you selected when setting up the LDAP server.
  5. Click Save.

Next, your system needs to know where in the LDAP database to find users :

  1. Click on LDAP Search Bases.
  2. In the Global search base field, enter your server’s base DN, like dc=foo,dc=com .
  3. In Base for Unix users enter the DN for your users’ sub-tree, like dc=Users,dc=foo,dc=com .
  4. Enter the same DN in Base for Unix passwords.
  5. Similarly, in Base for Unix groups enter dc=Groups,dc=foo,dc=com .
  6. Click Save.

At this point, you should be able to click on the LDAP Browser icon in this module and see the user and group sub-trees in your database. If it displays an error, check the settings made in the steps above.

Finally, the system has to be told to use LDAP to find user and group details. To enable this :

  1. Click on Services Using LDAP.
  2. Click the Unix users entry in the table. On the page that appears, next to Second data sourceselect LDAP, then hit Save.
  3. Do the same for Unix groups and Unix shadow passwords.

To verify that everything is really working, click the Validate Configuration button on the main page of the LDAP Client module. It should find and display the example Unix user that was created when you setup your LDAP server. If not, use the error message to work out what might have gone wrong.

If you get an error like user does not exist even when you are sure everything is correct, try restarting Webmin with the /etc/webmin/restart command run as root at the command line. On some systems, user and group data sources are cached by running server processes until they are restarted.

These same steps can be repeated on any other system on your network that should share users and groups. Naturally, they will also need to NSS and PAM LDAP modules installed too. These other systems should share the base directory for users’ homes (typically /home) via NFS, so that users can login to any LDAP client and access their files.

On some systems (notably Debian and Ubuntu), the www-data user Apache runs as cannot be a member of any domains’ groups, which prevents websites from working in a default Virtualmin setup. To fix this, edit the /etc/ldap.conf file, find the nss_initgroups_ignoreusers line and remove www-data from it.

NFS can be setup by using the NFS Exports module to share /home to the other client systems, and theDisk and Network Filesystems module on clients to add an NFS filesystem that mounts it. Typically one system will be both the LDAP and NFS server, but that doesn’t strictly have to be case, as long as they can all write to /home.

Setting up PAM

PAM has it’s own configuration files that determine when LDAP is used to check and change passwords. Unless they are setup, users created in LDAP will exist but will not be able to login. A command like id -a example will display a user from LDAP, but you will not be able to change his password with a command like passwd example.

This can be setup in Webmin’s PAM Authentication module, found under the System Category. The exact steps to take differ slightly between Redhat-based and Debian-based distributions though. Once they are done, you should be able to use the passwd command to set a password for the example user.

PAM Setup On Debian and Ubuntu

Debian-based systems have a separate PAM include file for each step. LDAP support needs to be added to each as follows :

  1. Click on common-account in the list of services.
  2. Select pam_ldap.so from the Add step for menu, then click the button.
  3. Change the Failure level to Sufficient, then click Create.
  4. Use the up arrow to move the new pam_ldap.so step above the existing pam_unix.so entry.

These same steps should then be repeated for the common-auth, common-password and common-session services.

PAM Setup on CentOS, Fedora and Redhat

Redhat-based systems have a single common PAM service that is called by all others. LDAP support can be added to it as follows :

  1. Click on system-auth in the list of services.
  2. In the Authentication steps section, select pam_ldap.so from the Add step for menu, then click the button.
  3. Change the Failure level to Sufficient, then click Create.
  4. Use the up arrow to move the new pam_ldap.so step above the existing pam_unix.so entry.
  5. Repeat 1,2 and 3 in the Account verification, Session setup and Password change steps on the same page.

Setting Up Webmin’s LDAP Users and Groups Module

Even though you could theoretically add a user to an LDAP database using the LDAP Server module’s browser, it is much easier to use a Webmin module that takes care of selecting all the correct attributes for you. The LDAP Users and Groups module under the System category is similar to the more commonly used Users and Groups module, but operates directly on a local or remote LDAP database.

Assuming that your system has been setup as an LDAP client, when you open the module it should display a list of existing users and groups, including the example user. If it displays an error about connecting to the database or searching for users, you may need to adjust settings on the Module Config page.

To ensure that user creation is working, try clicking on Add a new LDAP user, filling in the Username,Real name and Password, and clicking Create. If the user is added to the list with no errors, and if you can SSH into the system as the user, congratulations!

If you get an error like no strucutural object class provided when adding a user, the cause is almost certainly that your LDAP schema requires that users have the person object class. Webmin versions 1.404 and later add this automatically, but to have it added in older versions you should do the following :

  1. Click on the Module Config link, and enter person in the Other objectClasses to add to new users field.
  2. Go to the LDAP attributes section, and in the LDAP properties for all new users box enter
sn: ${REAL}
  1. Click Save.
  2. Re-try creating a user.

Creating LDAP Users with Virtualmin

Once the LDAP Users and Groups module is working, you can configure Virtualmin to add new domain users and mailboxes to LDAP instead of files in /etc. This can be done as follows :

  1. Open the System Settings category on Virtualmin’s left menu, and click on Module Config.
  2. Change Store users and groups to LDAP database, and click Save.
  3. If prompted, click the button to re-check the Virtualmin configuration.
  4. Go to Webmin’s Bootup and Shutdown module under the System category, and look for an nscdaction. If you see it, check the box next to it and then click Disable Now and On Boot. The Name Service Caching Daemon causes problems for Virtualmin, as it adds delay between when a user is added to the database and when it becomes visible to other programs.

Any domains or mailboxes created from now on will be added to LDAP. To avoid confusion, I suggest only making this change on a system that isn’t hosting any domains yet, so that they are all added to the same database.

The most common error is something like failed to create administration user or administration user was created but does not exist. This means that Virtualmin added an LDAP entry successfully, but when it used the getpwnam system call to check if the user is really known to Unix, he was not found. The most common cause is an incorrect LDAP client configuration, which should be revealed by the Validation Configuration button in the LDAP Client module. Another common cause is the nscd daemon, which adds a delay before users are visible and should be disabled.

Storing Email Aliases in LDAP

Just as users and groups can be stored in LDAP, so can email aliases used by mail servers like Postfix. These can then be read by multiple mail servers sharing the same configuration, to distribute the mail delivery load.

These instructions assume that you already have a working LDAP server as explained above, but don’t require that the system be setup to use LDAP for users or groups. Also, only Postfix is covered (even though Sendmail has similar capabilities), as only the Postfix Webmin module supports LDAP at the time of writing.

Postfix’s LDAP Suppport

Postfix stores aliases, virtual address mappings and other configuration tables in maps, which are typically DBM format files built from text files. However, with the right plugin modules it can use a MySQL or LDAP database instead, which can be queried over the network.

On Debian or Ubuntu systems, the command to install LDAP support for Postfix is :

apt-get install postfix-ldap

On other systems, Postfix may come with LDAP support already enabled. If not, you may need to download and compile it manually. To check if your Postfix supports LDAP, run the command :

postconf -m

and look for ldap in the output.

Setting up the LDAP Schema

I’ve found that there doesn’t seem to be any consistent agreement on which LDAP object class and attributes to use for Postfix objects. However, the misc schema that comes with OpenLDAP defines ainetLocalMailRecipient class that is almost good enough.

To configure the schema fully, do the following :

  1. Go to the LDAP Server module, and click on Manage Schema.
  2. Check the box next to the misc schema (if it isn’t already), and click Save.
  3. Go back to the schema page, and click the Edit link next to the misc schema.
  4. Find the definition for the inetLocalMailRecipient class, which should be like :
    objectclass ( 2.16.840.1.113730.3.2.147
    	NAME 'inetLocalMailRecipient'
    	DESC 'Internet local mail recipient'
    	SUP top AUXILIARY
    	MAY	( mailLocalAddress $ mailHost $ mailRoutingAddress ) )
  5. Change the AUXILIARY to STRUCTURAL, and click Save.
  6. Go back to the module’s main page, and click Apply Configuration.

Creating LDAP Trees for Postfix

Each Postfix map should have a separate sub-tree in the LDAP database. With Virtualmin, you will need at least trees for the alias and virtual maps, which can be created as follows :

  1. Click on Create Tree.
  2. Select Distinguished name, and in the adjacent field enter something likedc=Aliases,dc=foo,dc=com.
  3. Click Create.
  4. Repeat these steps to create the dc=Virtual,dc=foo,dc=com tree.

Configuring the Webmin Postfix Module

Now that the LDAP server is set, Postfix has to be told to talk to it. The first step is to have it use the correct LDAP object class, by doing :

  1. Go to the Postfix Mail Server module, and click on Module Config.
  2. Find the LDAP options section.
  3. Change the Object classes for maps to inetLocalMailRecipient .
  4. Change the Key attribute for map objects to mailLocalAddress .
  5. For Create separate DN for each domain?, select No .
  6. Click Save.

Now you need to edit the maps for aliases and virtual domains to add LDAP data sources, as follows :

  1. Go to the Postfix Mail Server module, and click on Mail Aliases.
  2. Click the … button next to Alias databases used by the local delivery agent. By default, this field will just contain something like hash:/etc/aliases.
  3. In the popup window, scroll down to the Map source 2 section and select LDAP server.
  4. Enter your LDAP server’s hostname in the LDAP server hosts field.
  5. Set the LDAP search base DN to the DN you created previously, such asdc=Aliases,dc=foo,dc=com .
  6. Set the Query filter to mailLocalAddress=%s .
  7. Set the Result attribute to mailRoutingAddress .
  8. In the Server login field, enter your LDAP server’s administration login, likecn=Manager,dc=foo,dc=com .
  9. Enter the LDAP administration password in the Server password field.
  10. Click Save at the bottom of the popup window.
  11. Click Save again back on the Mail Aliases page.

It is also possible to use a different login, such as an LDAP account who just has read-write access to the aliases sub-tree.

You must now do the same thing on the Virtual Domains page. The only difference should be in the LDAP search base DN field, which should be set to something like dc=Virtual,dc=foo,dc=com .

To verify that everything is working, try adding an alias using Webmin and ensure that it shows up in the list of aliases. Then send email to the new alias, and check that it is forwarded correctly. If not, check the Postfix logs in /var/log/mail* for errors that explain why it couldn’t talk to the LDAP database.

Creating LDAP Aliases with Virtualmin

Once Webmin’s Postfix module is configured to use LDAP, Virtualmin should automatically detect this and create any new aliases in the same LDAP database. To verify that it is all working, click on Re-Check Config on the left menu, and look for any messages about problems talking to the database server.

If that all checks out OK, try adding a mail aliases in Virtualmin, sending email to it, and verifying that it is delivered OK. Do the same for a mailbox user, as each has at least one virtual map entry for his address.

If you plan to run more than one mail server, each must have the same LDAP map configuration. This can be simplified by just copying across the configuration files in /etc/postfix that you will see referenced in the map definitions.

Ubuntu Linux OpenSSH Server installation and configuration

Q. I have just installed Ubuntu 6.06 and I would like to allow remote login to my system from home via ssh. How do I install and configure SSH server?

A. OpenSSH is a FREE version of the SSH connectivity tools that technical users of the Internet rely on. Users of telnet, rlogin, and ftp may not realize that their password is transmitted across the Internet unencrypted, but it is. OpenSSH encrypts all traffic (including passwords) to effectively eliminate eavesdropping, connection hijacking, and other attacks. Additionally, OpenSSH provides secure tunneling capabilities and several authentication methods, and supports all SSH protocol versions.

Ubuntu SSHD Installation

Type the following two command to install both ssh client and server:
# sudo apt-get install openssh-server openssh-client

SSHD Configuration

To be frank your server is ready by default. Just test it from your home computer or from same system with the command:
# ssh localhost
OR
# ssh user@your-server-ip-address

How do I use ssh client?

Assuming that your server hostname is userver.mydomain.com and username is vivek, you need to type the following command:
# ssh vivek@userver.mydomain.com
To stop ssh server, enter:
# sudo /etc/init.d/ssh stop
To start sshs server, enter:
# sudo /etc/init.d/ssh start
To restart ssh server, enter:
# sudo /etc/init.d/ssh restart

DovecotLDAP

Introduction

This guide will help you configure the Dovecot IMAP/POP3 server program to use LDAP for user authentication.

Prerequisites

It’s probably a good idea to install and configure Dovecot first without using LDAP that way you’ll be sure to have a working installation to go back to. To install and configure Dovecot to use the Linux system users follow the Dovecot guide.

The next thing you’ll need is a working LDAP server. This guide is written using OpenLDAP, but Dovecot can be configured to use other LDAP servers. For instructions on installing and configuring OpenLDAP see the OpenLDAPServer page.

Configuration

/etc/dovecot/dovecot-ldap.conf

To configure Dovecot to use LDAP first edit /etc/dovecot/dovecot-ldap.conf this file contains details about your LDAP server.

The first setting you’ll need to set is host this is the hostname or IP Address of the machine running your LDAP server:

host = ldap.example.org

The next setting needed is dn and dnpass this is the DN of the user used to connect to and search through the LDAP directory.

dn = cn=Manager,dc=example,dc=org
dnpass = secret

If you’ve configured you’re LDAP server to use TLS set the tls setting to yes:

tls = yes

This will encrypt traffic between Dovecot and your LDAP server. This option is highly recommended if your Dovecot server is on a different machine than your LDAP server.

  • Note: This option is not available with the version of Dovecot shipped with Ubuntu 6.06 (Dapper), Ubuntu 6.10 (Edgy), or Ubuntu 7.04 (Feisty).

To verify the user’s password set the auth_bind setting. Dovecot will bind to the LDAP directory using the mail client user’s credentials.

auth_bind = yes

If your users are set up under one area in your LDAP directory set the auth_bind_userdn setting. This will save a LDAP request per login, but isn’t strictly necessary.

auth_bind_userdn = cn=%u,ou=People,dc=example,dc=org

In this example all user objects are under the People OU in the directory.

Depending on how you’ve configured your LDAP server you’ll need to set the ldap_version setting appropriately:

ldap_version = 3

LDAP version 3 is the latest version of the protocol, but depending on if you have legacy applications you may be using LDAP version 2 as well.

Next set the LDAP search base. This setting configures where to start searching through your LDAP directory. This could be the same as the auth_bind setting. Also related to searching the directory is the scope setting. Set this if you want to search through sub objects of your directory. For example if you have an OU named Executives inside the People OU you’d set scope setting tosubtree

base = ou=People, dc=example, dc=org
scope = subtree

You need to tell Dovecot wich LDAP attributes map to Dovecot settings uid, gid, home, and mail. This is done with the user_attrssetting:

user_attrs = homeDirectory=home,uidNumber=uid,gidNumber=gid

The user_filter setting will be used when Dovecot searches LDAP for user accounts:

user_filter = (&(objectClass=posixAccount)(uid=%u))

The %u will be replaced by the user’s username entered into their mail client.

Dovecot also needs to know which LDAP attributes are associated with the user’s password. Similar to the user_attrs setting this is done with the pass_attrs setting:

pass_attrs = uid=user,userPassword=password

Like the user_filter you need to set the pass_filter setting:

pass_filter = (&(objectClass=posixAccount)(uid=%u))

Just as with the user_filter the %u is replaced with the username.

/etc/dovecot/dovecot.conf

Now that Dovecot knows the details of your LDAP server you need to configure Dovecot to use it. This is done by editing the/etc/dovecot/dovecot.conf file.

The first setting to change is under the auth_default section passwd ldap:

  # LDAP database
  passdb ldap {
  # Path for LDAP configuration file, see doc/dovecot-ldap.conf for example
    args = /etc/dovecot/dovecot-ldap.conf
  }

This setting tells Dovecot to use LDAP to lookup passwords.

Next the user ldap setting, which tells Dovecot to use LDAP to find users, needs to be configured:

  # LDAP database
  userdb ldap {
    # Path for LDAP configuration file, see doc/dovecot-ldap.conf for example
    args = /etc/dovecot/dovecot-ldap.conf
  }

Testing

Now that Dovecot is configured to use LDAP it’ll need to be restarted to use the new settings:

/etc/init.d/dovecot restart

To test that Dovecot is indeed using LDAP for user authentication simply configure a mail client to connect to the server using either IMAP or POP3 (whichever you’ve configured Dovecot to serve). If all goes well you should be able to login and get email.

Another way to test is to start slapd in a console session with debug output:

/etc/init.d/slapd stop (this will stop slapd in case it's already running)
slapd -f /etc/ldap/slapd.conf -d -1

Whenever a user connects to Dovecot you should see the LDAP debug output in the console window.

  • This is also a great way to make sure you’ve configured Dovecot to use LDAP correctly.

Note: This guide has been tested on Ubuntu 6.06 (Dapper), Ubuntu 7.04 (Feitsy), and Ubuntu (Gutsy).

SSH server

Introduction

This section of the Ubuntu Server Guide introduces a powerful collection of tools for the remote control of networked computers and transfer of data between networked computers, called OpenSSH. You will also learn about some of the configuration settings possible with the OpenSSH server application and how to change them on your Ubuntu system.

OpenSSH is a freely available version of the Secure Shell (SSH) protocol family of tools for remotely controlling a computer or transferring files between computers. Traditional tools used to accomplish these functions, such as telnet orrcp, are insecure and transmit the user’s password in cleartext when used. OpenSSH provides a server daemon and client tools to facilitate secure, encrypted remote control and file transfer operations, effectively replacing the legacy tools.

The OpenSSH server component, sshd, listens continuously for client connections from any of the client tools. When a connection request occurs, sshd sets up the correct connection depending on the type of client tool connecting. For example, if the remote computer is connecting with the ssh client application, the OpenSSH server sets up a remote control session after authentication. If a remote user connects to an OpenSSH server with scp, the OpenSSH server daemon initiates a secure copy of files between the server and client after authentication. OpenSSH can use many authentication methods, including plain password, public key, and Kerberos tickets.

Installation

Installation of the OpenSSH client and server applications is simple. To install the OpenSSH client applications on your Ubuntu system, use this command at a terminal prompt:

sudo apt-get install openssh-client

To install the OpenSSH server application, and related support files, use this command at a terminal prompt:

sudo apt-get install openssh-server

The openssh-server package can also be selected to install during the Server Edition installation process.

Configuration

You may configure the default behavior of the OpenSSH server application, sshd, by editing the file/etc/ssh/sshd_config. For information about the configuration directives used in this file, you may view the appropriate manual page with the following command, issued at a terminal prompt:

man sshd_config

There are many directives in the sshd configuration file controlling such things as communication settings and authentication modes. The following are examples of configuration directives that can be changed by editing the/etc/ssh/sshd_config file.

Prior to editing the configuration file, you should make a copy of the original file and protect it from writing so you will have the original settings as a reference and to reuse as necessary.

Copy the /etc/ssh/sshd_config file and protect it from writing with the following commands, issued at a terminal prompt:

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.original
sudo chmod a-w /etc/ssh/sshd_config.original

The following are examples of configuration directives you may change:

  • To set your OpenSSH to listen on TCP port 2222 instead of the default TCP port 22, change the Port directive as such:

    Port 2222

  • To have sshd allow public key-based login credentials, simply add or modify the line:

    PubkeyAuthentication yes

    In the /etc/ssh/sshd_config file, or if already present, ensure the line is not commented out.

  • To make your OpenSSH server display the contents of the /etc/issue.net file as a pre-login banner, simply add or modify the line:

    Banner /etc/issue.net

    In the /etc/ssh/sshd_config file.

After making changes to the /etc/ssh/sshd_config file, save the file, and restart the sshd server application to effect the changes using the following command at a terminal prompt:

sudo /etc/init.d/ssh restart
Many other configuration directives for sshd are available for changing the server application’s behavior to fit your needs. Be advised, however, if your only method of access to a server is ssh, and you make a mistake in configuring sshd via the /etc/ssh/sshd_config file, you may find you are locked out of the server upon restarting it, or that the sshd server refuses to start due to an incorrect configuration directive, so be extra careful when editing this file on a remote server.

SSH Keys

SSH keys allow authentication between two hosts without the need of a password. SSH key authentication uses two keys a private key and a public key.

To generate the keys, from a terminal prompt enter:

ssh-keygen -t dsa

This will generate the keys using a DSA authentication identity of the user. During the process you will be prompted for a password. Simply hit Enter when prompted to create the key.

By default the public key is saved in the file ~/.ssh/id_dsa.pub, while ~/.ssh/id_dsa is the private key. Now copy theid_dsa.pub file to the remote host and append it to ~/.ssh/authorized_keys by entering:

ssh-copy-id username@remotehost

Finally, double check the permissions on the authorized_keys file, only the authenticated user should have read and write permissions. If the permissions are not correct change them by:

chmod 644 .ssh/authorized_keys

You should now be able to SSH to the host without being prompted for a password.

FTP server

File Transfer Protocol (FTP) is a TCP protocol for uploading and downloading files between computers. FTP works on a client/server model. The server component is called an FTP daemon. It continuously listens for FTP requests from remote clients. When a request is received, it manages the login and sets up the connection. For the duration of the session it executes any of commands sent by the FTP client.

Access to an FTP server can be managed in two ways:

  • Anonymous
  • Authenticated

In the Anonymous mode, remote clients can access the FTP server by using the default user account called “anonymous” or “ftp” and sending an email address as the password. In the Authenticated mode a user must have an account and a password. User access to the FTP server directories and files is dependent on the permissions defined for the account used at login. As a general rule, the FTP daemon will hide the root directory of the FTP server and change it to the FTP Home directory. This hides the rest of the file system from remote sessions.

vsftpd – FTP Server Installation

vsftpd is an FTP daemon available in Ubuntu. It is easy to install, set up, and maintain. To install vsftpd you can run the following command:

sudo apt-get install vsftpd

Anonymous FTP Configuration

By default vsftpd is configured to only allow anonymous download. During installation a ftp user is created with a home directory of /home/ftp. This is the default FTP directory.

If you wish to change this location, to /srv/ftp for example, simply create a directory in another location and change theftp user’s home directory:

sudo mkdir /srv/ftp
sudo usermod -d /srv/ftp ftp

After making the change restart vsftpd:

sudo /etc/init.d/vsftpd restart

Finally, copy any files and directories you would like to make available through anonymous FTP to /srv/ftp.

User Authenticated FTP Configuration

To configure vsftpd to authenticate system users and allow them to upload files edit /etc/vsftpd.conf:

local_enable=YES
write_enable=YES

Now restart vsftpd:

sudo /etc/init.d/vsftpd restart

Now when system users login to FTP they will start in their home directories where they can download, upload, create directories, etc.

Similarly, by default, the anonymous users are not allowed to upload files to FTP server. To change this setting, you should uncomment the following line, and restart vsftpd:

anon_upload_enable=YES
Enabling anonymous FTP upload can be an extreme security risk. It is best to not enable anonymous upload on servers accessed directly from the Internet.

The configuration file consists of many configuration parameters. The information about each parameter is available in the configuration file. Alternatively, you can refer to the man page, man 5 vsftpd.conf for details of each parameter.

Securing FTP

There are options in /etc/vsftpd.conf to help make vsftpd more secure. For example users can be limited to their home directories by uncommenting:

chroot_local_user=YES

You can also limit a specific list of users to just their home directories:

chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list

After uncommenting the above options, create a /etc/vsftpd.chroot_list containing a list of users one per line. Then restart vsftpd:

sudo /etc/init.d/vsftpd restart

Also, the /etc/ftpusers file is a list of users that are disallowed FTP access. The default list includes root, daemon, nobody, etc. To disable FTP access for additional users simply add them to the list.

FTP can also be encrypted using FTPS. Different from SFTP, FTPS is FTP over Secure Socket Layer (SSL). SFTP is a FTP like session over an encrypted SSH connection. A major difference is that users of SFTP need to have a shellaccount on the system, instead of a nologin shell. Providing all users with a shell may not be ideal for some environments, such as a shared web host.

To configure FTPS, edit /etc/vsftpd.conf and at the bottom add:

ssl_enable=Yes

Also, notice the certificate and key related options:

rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key

By default these options are set the certificate and key provided by the ssl-cert package. In a production environment these should be replaced with a certificate and key generated for the specific host. For more information on certificates see the section called “Certificates”.

Now restart vsftpd, and non-anonymous users will be forced to use FTPS:

sudo /etc/init.d/vsftpd restart

To allow users with a shell of /usr/sbin/nologin access to FTP, but have no shell access, edit /etc/shells adding thenologin shell:

# /etc/shells: valid login shells
/bin/csh
/bin/sh
/usr/bin/es
/usr/bin/ksh
/bin/ksh
/usr/bin/rc
/usr/bin/tcsh
/bin/tcsh
/usr/bin/esh
/bin/dash
/bin/bash
/bin/rbash
/usr/bin/screen
/usr/sbin/nologin

This is necessary because, by default vsftpd uses PAM for authentication, and the /etc/pam.d/vsftpd configuration file contains:

auth    required        pam_shells.so

The shells PAM module restricts access to shells listed in the /etc/shells file.

Most popular FTP clients can be configured connect using FTPS. The lftp command line FTP client has the ability to use FTPS as well.

Postfix

Postfix is the default Mail Transfer Agent (MTA) in Ubuntu. It attempts to be fast and easy to administer and secure. It is compatible with the MTA sendmail. This section explains how to install and configure postfix. It also explains how to set it up as an SMTP server using a secure connection (for sending emails securely).

This guide does not cover setting up Postfix Virtual Domains, for information on Virtual Domains and other advanced configurations see the section called “References”.

Installation

To install postfix run the following command:

sudo apt-get install postfix

Simply press return when the installation process asks questions, the configuration will be done in greater detail in the next stage.

Basic Configuration

To configure postfix, run the following command:

sudo dpkg-reconfigure postfix

The user interface will be displayed. On each screen, select the following values:

  • Internet Site
  • mail.example.com
  • steve
  • mail.example.com, localhost.localdomain, localhost
  • No
  • 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.0/24
  • 0
  • +
  • all
Replace mail.example.com with the domain for which you’ll accept email, 192.168.0/24 with the actual network and class range of your mail server, and steve with the appropriate username.

Now is a good time to decide which mailbox format you want to use. By default Postfix will use mbox for the mailbox format. Rather than editing the configuration file directly, you can use the postconf command to configure all postfixparameters. The configuration parameters will be stored in /etc/postfix/main.cf file. Later if you wish to re-configure a particular parameter, you can either run the command or change it manually in the file.

To configure the mailbox format for Maildir:

sudo postconf -e 'home_mailbox = Maildir/'
This will place new mail in /home/username/Maildir so you will need to configure your Mail Delivery Agent (MDA) to use the same path.

SMTP Authentication

SMTP-AUTH allows a client to identify itself through an authentication mechanism (SASL). Transport Layer Security (TLS) should be used to encrypt the authentication process. Once authenticated the SMTP server will allow the client to relay mail.

  1. Configure Postfix for SMTP-AUTH using SASL (Dovecot SASL):
    sudo postconf -e 'smtpd_sasl_type = dovecot'
    sudo postconf -e 'smtpd_sasl_path = private/auth-client'
    sudo postconf -e 'smtpd_sasl_local_domain ='
    sudo postconf -e 'smtpd_sasl_security_options = noanonymous'
    sudo postconf -e 'broken_sasl_auth_clients = yes'
    sudo postconf -e 'smtpd_sasl_auth_enable = yes'
    sudo postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'
    sudo postconf -e 'inet_interfaces = all'
    The smtpd_sasl_path configuration is a path relative to the Postfix queue directory.
  2. Next, obtain a digital certificate for TLS. See the section called “Certificates” for details. This example also uses a Certificate Authority (CA). For information on generating a CA certificate see the section called “Certification Authority”.
    You can get the digital certificate from a certificate authority. But unlike web clients, SMTP clients rarely complain about “self-signed certificates”, so alternatively, you can create the certificate yourself. Refer to the section called “Creating a Self-Signed Certificate” for more details.
  3. Once you have a certificate, configure Postfix to provide TLS encryption for both incoming and outgoing mail:
    sudo postconf -e 'smtpd_tls_auth_only = no'
    sudo postconf -e 'smtp_use_tls = yes'
    sudo postconf -e 'smtpd_use_tls = yes'
    sudo postconf -e 'smtp_tls_note_starttls_offer = yes'
    sudo postconf -e 'smtpd_tls_key_file = /etc/ssl/private/server.key'
    sudo postconf -e 'smtpd_tls_cert_file = /etc/ssl/certs/server.crt'
    sudo postconf -e 'smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem'
    sudo postconf -e 'smtpd_tls_loglevel = 1'
    sudo postconf -e 'smtpd_tls_received_header = yes'
    sudo postconf -e 'smtpd_tls_session_cache_timeout = 3600s'
    sudo postconf -e 'tls_random_source = dev:/dev/urandom'
    sudo postconf -e 'myhostname = mail.example.com'
After running all the commands, Postfix is configured for SMTP-AUTH and a self-signed certificate has been created for TLS encryption.

Now, the file /etc/postfix/main.cf should look like this.

The postfix initial configuration is complete. Run the following command to restart the postfix daemon:

Postfix supports SMTP-AUTH as defined in RFC2554. It is based on SASL. However it is still necessary to set up SASL authentication before you can use SMTP-AUTH.

Configuring SASL

Postfix supports two SASL implementations Cyrus SASL and Dovecot SASL. To enable Dovecot SASL the dovecot-common package will need to be installed. From a terminal prompt enter the following:

sudo apt-get install dovecot-common

Next you will need to edit /etc/dovecot/dovecot.conf. In the auth default section uncomment the socket listen option and change the following:

  socket listen {
    #master {
      # Master socket provides access to userdb information. It's typically
      # used to give Dovecot's local delivery agent access to userdb so it
      # can find mailbox locations.
      #path = /var/run/dovecot/auth-master
      #mode = 0600
      # Default user/group is the one who started dovecot-auth (root)
      #user = 
      #group = 
    #}
    client {
      # The client socket is generally safe to export to everyone. Typical use
      # is to export it to your SMTP server so it can do SMTP AUTH lookups
      # using it.
      path = /var/spool/postfix/private/auth-client
      mode = 0660
      user = postfix
      group = postfix
    }
  }

In order to let Outlook clients use SMTPAUTH, in the auth default section of /etc/dovecot/dovecot.conf add “login”:

  mechanisms = plain login

Once you have Dovecot configured restart it with:

sudo /etc/init.d/dovecot restart

Postfix-Dovecot

Another option for configuring Postfix for SMTP-AUTH is using the dovecot-postfix package. This package will installDovecot and configure Postfix to use it for both SASL authentication and as a Mail Delivery Agent (MDA). The package also configures Dovecot for IMAP, IMAPS, POP3, and POP3S.

You may or may not want to run IMAP, IMAPS, POP3, or POP3S on your mail server. For example, if you are configuring your server to be a mail gateway, spam/virus filter, etc. If this is the case it may be easier to use the above commands to configure Postfix for SMTPAUTH.

To install the package, from a terminal prompt enter:

sudo apt-get install dovecot-postfix

You should now have a working mail server, but there are a few options that you may wish to further customize. For example, the package uses the certificate and key from the ssl-cert package, and in a production environment you should use a certificate and key generated for the host. See the section called “Certificates” for more details.

Once you have a customized certificate and key for the host, change the following options in /etc/postfix/main.cf:

smtpd_tls_cert_file = /etc/ssl/certs/ssl-mail.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-mail.key

Then restart Postfix:

sudo /etc/init.d/postfix restart

Testing

SMTP-AUTH configuration is complete. Now it is time to test the setup.

To see if SMTP-AUTH and TLS work properly, run the following command:

telnet mail.example.com 25

After you have established the connection to the postfix mail server, type:

ehlo mail.example.com

If you see the following lines among others, then everything is working perfectly. Type quit to exit.

250-STARTTLS
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250 8BITMIME

Troubleshooting

This section introduces some common ways to determine the cause if problems arise.

Escaping chroot

The Ubuntu postfix package will by default install into a chroot environment for security reasons. This can add greater complexity when troubleshooting problems.

To turn off the chroot operation locate for the following line in the /etc/postfix/master.cf configuration file:

smtp      inet  n       -       -       -       -       smtpd

and modify it as follows:

smtp      inet  n       -       n       -       -       smtpd

You will then need to restart Postfix to use the new configuration. From a terminal prompt enter:

sudo /etc/init.d/postfix restart

Log Files

Postfix sends all log messages to /var/log/mail.log. However error and warning messages can sometimes get lost in the normal log output so they are also logged to /var/log/mail.err and /var/log/mail.warn respectively.

To see messages entered into the logs in real time you can use the tail -f command:

tail -f /var/log/mail.err

The amount of detail that is recorded in the logs can be increased. Below are some configuration options for increasing the log level for some of the areas covered above.

  • To increase TLS activity logging set the smtpd_tls_loglevel option to a value from 1 to 4.
    sudo postconf -e 'smtpd_tls_loglevel = 4'
  • If you are having trouble sending or receiving mail from a specific domain you can add the domain to thedebug_peer_list parameter.
    sudo postconf -e 'debug_peer_list = problem.domain'
  • You can increase the verbosity of any Postfix daemon process by editing the /etc/postfix/master.cf and adding a -v after the entry. For example edit the smtp entry:
    smtp      unix  -       -       -       -       -       smtp -v
It is important to note that after making one of the logging changes above the Postfix process will need to be reloaded in order to recognize the new configuration: sudo /etc/init.d/postfix reload
  • To increase the amount of information logged when troubleshooting SASL issues you can set the following options in /etc/dovecot/dovecot.conf
    auth_debug=yes
    auth_debug_passwords=yes
Just like Postfix if you change a Dovecot configuration the process will need to be reloaded: sudo /etc/init.d/dovecot reload.
Some of the options above can drastically increase the amount of information sent to the log files. Remember to return the log level back to normal after you have corrected the problem. Then reload the appropriate daemon for the new configuration to take affect.

References

Administering a Postfix server can be a very complicated task. At some point you may need to turn to the Ubuntu community for more experienced help.

A great place to ask for Postfix assistance, and get involved with the Ubuntu Server community, is the #ubuntu-server IRC channel on freenode. You can also post a message to one of the Web Forums.

For in depth Postfix information Ubuntu developers highly recommend: The Book of Postfix.

Finally, the Postfix website also has great documentation on all the different configuration options available.

Create your own website, free on WordPress.com.Create your own website.
Start free