Showing posts with label vsftpd. Show all posts
Showing posts with label vsftpd. Show all posts

Monday, June 27, 2011

500 OOPS: SSL: cannot load RSA certificate

I recently setup a vsftpd 2.2.2 server running on Ubuntu Server 10.04 LTS that required SSL connections for the login and data transfer, however I wasn’t able to get the commercial SSL certificate from Comodo (InstantSSL) to work with the service. I later found out that I needed to concatenate the certificate that I received from Comodo with their latest bundle certificate, which I blogged about here before. However, I personally still couldn’t get this to work after much trial and error. When starting the vsftpd daemon from the command-line would produce the message “500 OOPS: SSL: cannot load RSA certificate”.

After a volley of email back and forth with Comodo Support over the past three weeks they helped me to isolate the problem. I was missing a single “-” at the end of my server certificate. At the end of your certificate it should have “—–END CERTIFICATE—–”, that’s five dashes on either side. I had four on the right-hand side, which prevented vsftpd from starting (although Apache never complained). I had searched on this error all over the Internet and never found a mention of this, so if you’re here searching on this error, check your dashes!

Friday, June 17, 2011

Ubuntu 10.04 and vsftpd configuration for virtual users

One of the labs that I work for wanted to have a shared file share that’s accessible from anywhere, from any of the clients they run. We ended up going with a FTPS configuration on Ubuntu using vsftpd. All of the users are considered “virtual users”, so they don’t have login privileges to the Ubuntu system, only the FTP daemon running (meaning no SSH, etc). Also, all users are working out of the same file share folder.

Since I had some trouble finding a good set of directions, I thought I’d write up what I did. First, because I’ll probably have to repeat it at some point, second because someone else might be looking for the same thing.

Requirements

  • Ubuntu 10.04 LTS
  • vsftpd 2.2.2+
  • SSL certificate, either self-signed or from a SSL provider

Install software

If you haven’t installed vsftpd yet, you’ll want to do this:

sudo apt-get install vsftpd

Next we need a database utility for creating the hashed username/password file that vsftpd will authenticate against:

sudo apt-get install db4.8-util

Create virtual users

Now we need to create a text file that will have your virtual users identified. Let’s start by creating a directory to store this in: sudo mkdir -p /etc/vsftpd

Now create the text file. This file will be turned into a hashed database file, so it’s OK that you’re typing out the password in clear text right now. sudo nano /etc/vsftpd/logins.txt

The file configuration is one line for the user account name, then the next line is the account password. Repeat this for each user in a single monolithic file. For example:

    mary
    das2hky434adfg6yjkaf
    peter
    uh4nufh7ands
    paul
    ud674kr6d

Now we take this plain-text file and convert it to a database file with hashed passwords using the following command

sudo db_load -T -t hash -f /etc/vsftpd/logins.txt /etc/vsftpd/virtual-users.db

We should change the file permissions on both of these files, just to protect them from prying eyes:

sudo chmod 600 /etc/vsftpd/logins.txt
sudo chmod 600 /etc/vsftpd/virtual-users.db

Note: in the future if you need add/change/delete users, modify the logins.txt file and then use the db_load command to re-create the hashed database file.

Configure vsftpd

Now we need to configure the vsftpd daemon to use the correct directory, have the correct permissions and correctly authenticate our users.

Let’s create a single directory for the data files on our server

sudo mkdir -p /var/ftp-data

Make sure that your ftp service account (created when we installed vsftpd) has correct permissions for this directory

sudo chown -R ftp:ftp /var/ftp-data

Now we need to create a new type of authentication that vsftpd will use to verify our user logins. We do this by creating a new file in the PAM configuration folder

sudo nano /etc/pam.d/vsftpd-virtual

The file contents should be as follows, which tells the system to look at our hashed database for the user login/password combinations:

auth required pam_userdb.so db=/etc/vsftpd/virtual-users
account required pam_userdb.so db=/etc/vsftpd/virtual-users

Now we have to tell vsftpd about these new configurations, but first let’s make a backup of the configuration, then make a new one.

sudo mv /etc/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak
sudo nano /etc/vsftpd.conf

For the contents of this file, paste the following:

# runs vsftpd in standalone mode
listen=YES

# listens on this port for incoming FTP connections listen_port=21 # disables anonymous FTP anonymous_enable=NO # enables non-anonymous FTP local_enable=YES # enables uploads and new directories write_enable=YES # the umask for file creation local_umask=022 # Activate directory messages - messages given to remote users when they # go into a certain directory. dirmessage_enable=YES # If enabled, vsftpd will display directory listings with the time # in your local time zone. The default is to display GMT. The # times returned by the MDTM FTP command are also affected by this # option. use_localtime=YES # Activate logging of uploads/downloads. xferlog_enable=YES # Make sure PORT transfer connections originate from port 20 (ftp-data). connect_from_port_20=YES # the virtual user is restricted to the virtual FTP area chroot_local_user=YES # the PAM file used by authentication of virtual uses pam_service_name=vsftpd-virtual # SSL configuration directives rsa_cert_file=/etc/ssl/certs/server.crt rsa_private_key_file=/etc/ssl/private/server.key ssl_enable=YES force_local_logins_ssl=YES force_local_data_ssl=YES ssl_tlsv1=YES ssl_sslv2=NO ssl_sslv3=NO # the minimum port to allocate for PASV style data connections pasv_min_port=31000 # the maximum port to allocate for PASV style data connections pasv_max_port=31453 # activates virtual users guest_enable=YES # virtual users to use local privs, not anon privs virtual_use_local_privs=YES # specifies a home directory for all virtual users local_root=/var/ftp-data # hides the FTP server user ID, just show "ftp" in directory listings hide_ids=YES

Now we restart the vsftpd service for all of the changes to take place

sudo service vsftpd restart

Conclusion

If you have a SSL certificate in the directory outlined, then you should be able to login to the FTP service over SSL and have access to the directory we setup in /var/ftp-data.

In my case we also put this network share behind an Astaro Security Gateway (ASG), so first our users make an SSL VPN connection to the ASG, then make a SSL connection to the FTP server.

Wednesday, June 08, 2011

Hosting vsftpd (FTPS) server behind Astaro Security Gateway

At work we're moving from an internal Microsoft Windows hardware file server to a Ubuntu 10.04 LTS virtual server housed within the University data center. To provide secure, remote access to our shared files I've setup a vsftpd 2.2.2 FTP server that requires SSL for login and data transfer. This server lives "behind" an Astaro Security Gateway for protection.

I had some trouble with the setup of this initially, namely I could make a connection from outside on port 21, however I wasn't able to setup the data connection successfully to list the directory and perform transfers.

After much searching peppered with plenty of trial and error I was able to finally configure this setup correctly. Here is how I did it.

Server setup

  • Ubuntu 10.04 LTS server
  • vsftpd 2.2.2
  • Self-signed SSL certificate

Generate a 5 year self-signed certificate using 2048 bits

sudo openssl req -x509 -nodes -days 1825 -newkey rsa:2048 -keyout /etc/ssl/certs/vsftpd.pem -out /etc/ssl/certs/vsftpd.pem

Install the vsftpd server if you haven’t already

sudo apt-get install vsftpd

Configure the vsftpd server configuration file

sudo nano /etc/vsftpd.conf

Here we need to add the following lines at the end of the configuration file. Note that a key here is you define what your FTP PASV ports will be for data transfers. I’m using random values, so please select your own instead of just copying these:

    rsa_cert_file=/etc/ssl/certs/vsftpd.pem
    ssl_enable=YES
    force_local_logins_ssl=YES
    force_local_data_ssl=YES
    ssl_tlsv1=YES
    ssl_sslv2=NO
    ssl_sslv3=NO
    pasv_min_port=33423
    pasv_max_port=33500

Save the configuration file, then restart the vsftpd service

sudo /etc/init.d/vsftpd restart

Astaro Security Gateway v8.103 setup

In this example we’ll pretend the Astaro Security Gateway external interface has an IP of 1.1.1.1 and an additional IP address of 1.1.1.2 configured for just the traffic to go to the FTP server. You would configure the additional IP address for the external interface by going to:

  • Interfaces & Routing
  • Interfaces
  • Additional Addresses
  • New additional address…
  • Name = 1.1.1.2
  • On interface = External (WAN)
  • IPv4 Address = 1.1.1.2
  • Netmask = 255.0.0.0
  • Comment = my ftp server address
  • Save and make sure to enable the IP address by clicking on the green light to the left of the adapter graphic

Next we need to define a new service on the Astaro. This will be used to tell it what ports to expect the data connections on. We’ll be using the port range we specified earlier in the vsftpd.conf file. To setup this service, do the following:

  • Definitions
  • Services
  • New service definition…
  • Name = FTP-Data
  • Type of Definition = TCP
  • Destination port = 33423:33500
  • Source port = 1:65535
  • Comment = File Transfer Protocol Data
  • Save

OK, now we need to setup a definition for your internal FTP server that we’ll be exposing to the Internet. To do this, do the following:

  • Definitions
  • Networks
  • New network definition…
  • Name = ftp-server
  • Type = host
  • Interface = internal
  • IPv4 Address = 192.168.0.22
  • Comment = my internal ftp server
  • Save

Now that we’ve configured the system and service defintions we’ll actually create the rules to allow the inbound connections to the external IP address (1.1.1.2) to be passed to the internal IP address (192.168.0.22) using the FTP port (21) and respond back and allow data connections using the range we specified (33423 to 33500).

First we setup the destination NAT rule (DNAT) by doing the following:

  • Network Security
  • NAT
  • DNAT/SNAT
  • New NAT rule…
  • Traffic source = Any
  • Traffic service = FTP
  • Traffic destination = 1.1.1.2
  • NAT mode = DNAT (Destination)
  • Destination = ftp-server
  • Destination service = FTP
  • Save
  • New NAT rule…
  • Traffic source = Any
  • Traffic service = FTP-Data
  • Traffic destination = 1.1.1.2
  • NAT mode = DNAT (Destination)
  • Destination = ftp-server
  • Destination service = FTP-Data
  • Save

Make sure to enable both of these DNAT rules by clicking on the green light to the left of the DNAT rule number!

Lastly we’ll configure the packet filter rules to allow the traffic by doing the following:

  • Network Security
  • Packet Filter
  • New rule…
  • Source = Any
  • Service = FTP
  • Destination = ftp-server
  • Action = Allow
  • Save
  • New rule…
  • Source = Any
  • Service = FTP-Data
  • Destination = ftp-server
  • Action = Allow
  • Save

Again, make sure to enable both of these packet filter rules by clicking on the green light to the left of the packet filter rule number!

Client setup

On the two Mac systems we’re using the excellent Panic Transmit application. This allows us to access the share like a regular FTP server or mount the FTP server as a drive on the Mac (this is key for us). Create a new connection with the following parameters:

  • Protocol = FTP with TLS/SSL
  • Server = 1.1.1.2
  • User Name = whatever your Linux login account is
  • Password = whatever your Linux login password is
  • Port = 21
  • Use passive model = checked
  • Save

On the ten Windows systems we’re using NetDrive which allows us to mount the FTP server as a drive in Windows explorer (again, this is key for my users). Create a new connection with the following parameters:

  • Site name = 1.1.1.2
  • Site IP or URL = 1.1.1.2
  • Port = 21
  • Server Type = FTP
  • Drive = F
  • Account = whatever your Linux login account is
  • Password = whatever your Linux login password is
  • Save
  • Advanced
  • SSL = Force SSL for all communications
  • OK

Conclusion

That should have you setup and running now, able to access your internally hosted vsftpd server over SSL from external clients through the Astaro Security Gateway you have in front of the internal FTP server.

Using Comodo (InstantSSL) certificate with vsftpd (FTPS) server

I recently setup a vsftpd 2.2.2 server running on Ubuntu Server 10.04 LTS that required SSL connections for the login and data transfer, however I wasn’t able to get the commercial SSL certificate from Comodo (InstantSSL) to work with the service. The vsftpd daemon would start, but the client connections would fail.

It turns out the the problem is that Comodo certificates require the installation of a root and intermediate certificate for the issued certificate to work. Now that I know that, thanks to this knowledge base article it’s easy to fix. Here’s how to fix it on your server.

Download the Comodo bundle
sudo wget http://www.instantssl.com/ssl-certificate-support/cert_installation/bundle.crt -O ~/instantssl.crt
Concatenate certificates
sudo cat _your SSL certificate from Comodo_ ~/instantssl.crt >> ~/vsftpd.pem

Now configure your vsftpd.conf file to point to this new .pem file and restart the vsftpd service. Connections should now be using the valid certificate.