Proftpd is one of the most popular FTP servers for Linux. Easy to configure - it's usable right after installation.
WARNING:After installing proftpd we get full access to files and directories on the server!!!
That's why I would advise against leaving proftpd in its default configuration.
Before discussing the basic configuration, we need to ask ourselves: "who should our file server serve, and what resources should it expose?"
We have a choice of:
- system users - users who have shell account access on our server (trusted)
- ftp users - users who only have access to an FTP account (less trusted)
- anonymous users - users with access to so-called anonymous FTP, i.e. usually able to download files made available by the administrator without providing a login or password
We edit the proftpd.conf file:
# Include the configs of any activated modules.
Include /etc/proftpd/modules.conf
# Server operating mode, run as a standalone process.
ServerType standalone
# Set this configuration as the default one
DefaultServer on
# If we don't use IPv6.
UseIPv6 off
# These 3 options significantly shorten login time.
UseReverseDNS off
IdentLookups off
ServerIdent off
# We set our server name; we don't give its name or version.
ServerName "ftp by ulos.pl"
# Welcome message.
DisplayLogin welcome.msg
# We allow the welcome message only after logging in.
DeferWelcome on
MultilineRFC2228 on
# We allow displaying symlinks.
ShowSymlinks on
# Time after which the connection to the server will be terminated.
TimeoutNoTransfer 600
TimeoutStalled 600
TimeoutIdle 1200
DisplayChdir .message true
DenyFilter \*.*/
# Block root login.
RootLogin off
# Trap the user in a designated directory they can't escape from.
# the ~ sign is the home directory on Linux.
DefaultRoot ~
# Options for listing files in binary mode:
# "-a"="ls -a" , "+a"=block the a parameter, i.e. hidden files (starting with a dot).
ListOptions "+a"
# We check whether the user logging in
# has a shell assigned in /etc/shells (a quick way to block them).
RequireValidShell on
# The port on which proftpd listens.
Port 21
# Passive mode port configuration used by browsers (ftp://host.pl).
# PassivePorts 49152 65534
# A useful option if our computer is behind NAT.
# MasqueradeAddress 1.2.3.4
# This is useful for masquerading address with dynamic IPs:
# refresh any configured MasqueradeAddress directives every 8 hours
# DynMasqRefresh 28800
# Maximum number of FTP daemon processes.
# Thanks to this directive we can protect ourselves against DoS-type attacks.
MaxInstances 30
# The user and group the server process will belong to.
User proftpd
Group nogroup
# Setting owner access rights for modifying files and directories.
# 022 => 755 , 077 => 700 , 002 => 775
Umask 022 022
# Allow overwriting files.
AllowOverwrite on
# Log configuration.
TransferLog /var/log/proftpd/xferlog
SystemLog /var/log/proftpd/proftpd.log
Of course, after changing the proftpd.conf file, we restart the server.
This is an example of a basic proftpd configuration while maintaining certain security standards for
system users.
It's worth mentioning one more important thing: the FTP protocol sends passwords and logins in unencrypted form
, i.e. as so-called plain text, which makes it possible to eavesdrop on this fairly important information.
Now we'll deal with virtual users, who will only have an FTP account.
- The first step will be to create a directory for virtual users and give it the appropriate permissions. mkdir /home/ftp
- We create users using the ftpasswd tool:
chown proftpd:nobody /home/ftp
chmod 751 /home/ftp
ftpasswd --passwd --file /etc/proftpd/ftpd.passwd --name username --home /home/ftp/directory_name -p --uid ftp_user_id --gid ftp_group_id --shell /bin/falsewhere: ftp_user_id and ftp_group_id come from the proftpd.conf directives: User and Group
We can use a simple script that will save us from tediously typing so many parameters:
#!/bin/sh
if [ $# -lt 2 ] ; then
echo "pass the username as the first parameter, and their folder as the second parameter"
else
ftpasswd --passwd --file /etc/proftpd/.ftpd.passwd --name $1 --home /home/ftp/$2 -p --uid 106 --gid 65534 --shell /bin/false
mkdir -p /home/ftp/$2
chown -R proftpd:nogroup /home/ftp/$2
chmod 751 /home/ftp/$2
fi
We set the appropriate permissions: chmod 700 ftpcreate.sh We use it as follows: ./ftpcreate.sh username their_folder, after which it will ask for a password...
Let's also remember to modify the permissions of the ftpd.passwd file: chmod 600 .ftpd.passwd
We change the directive: RequireValidShell on to RequireValidShell off
At this point, the server handles both virtual and system users.