Pure-FTPd and DirectAdmin

A few days ago I set out to do a 5 minute task that turned into hours of head scratching, and some learning. This is the story of how I spent hours trying to set up an FTP account.

The task was really simple: set up a new ftp account on my server so that a client can upload files that will be processed by the system we are building. I thought I’d be done in 5 minutes. Just log in to the DirectAdmin (DA) panel, create a new account, and share the credentials. However, as it always happens, things did not go as planned. After setting up the new account I was unable to log in.

In the past, I had noticed that the system monitor in DA showed the ProFTPD service as stopped, but since I don’t really use FTP, and the existing FTP accounts worked well, I didn’t think much about it. But now it was time to pay a little more attention to that.

I went ahead and tried to restart the proftpd service

service proftpd restart

What was my surprise when the command came back saying that the service was not recognized. What is running the FTP then? Time to find out

service --status-all | grep "ftp"

I quickly learned that my server was in fact running Pure-FTPd, so I searched for its documentation. I learned about virtual users, which was my first nice piece of knowledge that I got this time, specially because in the past I had wondered how the FTP users worked in the server because there were no accounts that matched the FTP users. Back when I had a localhost running FTP for development I had to create system accounts for every FTP user I wanted to add, but not on this server.

Watching the log files I learned that 1) Mac’s finder will strip anything after, and including the @ symbol if it appears in the username, which was the case with my username. and 2) that once I started using an FTP client that did not have that behavior the server would just not let me in and all it said was that the authentication was wrong. This got me running in circles changing the password and typing it as carefully as I could just to make sure it was OK. But no luck.

Reading some stackoverflow answers I started experimenting with the pure-pw command, and it kept complaining that the /etc/pureftpd.passwd file was not found. There was however a /etc/proftpd.passwd file. I decided to re-create the Pure-FTPd database using that file.

pure-pw mkdb -f /etc/proftpd.passwd

After doing this I could finally log in via FTP. It took me about two hours to get to this point, and while I could just call it a day, send the credentials, and go home, something kept bugging me. Why would DA not be able to properly manage my FTP users. Also, at this point I had noticed that while I had changed the password for my FTP account not long ago after the first time I had issues with FTP, the password hadn’t actually been set. What was going on?


So, let me open this parenthesis to explained what happened before, and how this problem has been there for a while now without me noticing. A couple of weeks ago I was looking for some files that I thought may be on my server (they weren’t). I wanted to FTP into the server to see if the files were there. I could not FTP. Since it had been a long time since I had used the FTP account, I decided to just go into DA and reset the password, but no matter what I set the password to, I could not log in. Finally, I decided to contact support, and ask them to look into the problem. I changed the admin DA password to a temporary password, and sent it to them. They looked into the issue, and after some back and forth, they came back saying that the problem was fixed. When I asked what had happened, they just said there were inconsistencies with the login system. I went back into DA and changed the password again, but since I had already tested that the FTP account worked before changing the password, I didn’t bother to test again after changing the password. Yesterday I realized that password change hadn’t taken effect.


I now know that support simply set the password to what I told them the password was, which is why the account worked after they looked into the issue. However, they didn’t realize that changing the password in DA did not have any actual effect on the account.

At this point it became clear that DA thought it was dealing with ProFTPd, as evidenced by the system monitor saying ProFTPD was stopped. After reading documentation and experimenting I finally set the correct ftp setting on DA.

I should mention that I spent quite some time digging on the custom build script and learning a bit about its internals. But since I didn’t want to re-install the FTP service, I ended up using the directadmin binary to set the ftp configuration. You can also do this manually by editing the directadmin configuration file. Just like you can manage your ftp accounts by manually editting the passwd files.

directadmin set pureftpd 1 restart

After doing this, things now work correctly, except that DA insists on adding @domain.com to the FTP user names. That is something I was not able to get rid of from the DA panel, but I can easily edit the passwd file, change the name there, and rebuild the db. I just need to remember not to modify the FTP accounts from DA because that will bring the old username format back.

A couple of weeks ago I also had to set up an SFTP account, but that is a topic for another post. However, I’m mention it here because I want you to stay tuned for that article because using plain FTP is not recommended. Unfortunately, the client had issues on implementing a service that used that SFTP account, and requested a simple, plain, old FTP account. The data we are dealing with is not sensitive at all, and it is in fact information that we WANT to have available to the general public. We just want to present it in a nicer way, which is why we process it first. However, I do not recommend using plain FTP if you can avoid it. There are better options, such as FTPS and SFTP.

Fixing 500 OOPS: vsftpd: refusing to run with writable root inside chroot() on vsftpd

I was informed last night by one of my clients that he could not log into the server via ftp. I was surprised, and immediately blamed the new update (Ubuntu 12.04 LTS). This new update, updates vsftpd to 2.3.5, which tries now to be more secure by not allowing login with writable root directory. This does not affect my user, but if you remember from when we set up the new user, we added a list of users who would chroot() to their home directories. This directories are writable, so vsftpd is not allowing them to login.

The solution, as simple as it sounds, is to revoke writable permissions to this directories. Depending on how you have your system set up, this might not be the best solution for you. In my case it made no much difference. I have the user’s home directory set as wp-content, a directory inside any wordpress installation. My client only needs to be able to upload plugins, so giving him access to only that part of the server seemed like a good idea. The only thing I had to make sure of, is that he were not able to write to that file, so vsftpd would not complain. I did this:

chmod a-w /path/to/wp-content/
chmod u+w /path/to/wp-content/

First we remove write permissions for everybody, then add them only to the owner of the file, which in this case is not my client, but me. If the user you are trying to fix is the owner of the directory, don’t do the second line.

This fixes the problem, and you don’t even have to restart vsftpd.

Some references:
http://askubuntu.com/questions/128180/vsftpd-stopped-working-after-update

http://www.benscobie.com/fixing-500-oops-vsftpd-refusing-to-run-with-writable-root-inside-chroot/

I am a curious person, and this time I got curious about chroot, if you are curious too, read:
http://wiki.linuxquestions.org/wiki/Chroot
http://everyjoe.com/technology/explain-what-is-chroot/
https://help.ubuntu.com/community/BasicChroot
https://en.wikipedia.org/wiki/Chroot

Installing an FTP Server on Ubuntu

I had been postponing this task for some time now thinking that it would be time consuming. However, it is actually pretty simple.

Since I did not know of any FTP server, I did a quick search:

aptitude search ftp

I got a bunch of results but I decided to try vsftp after seeing somewhere that it was the default daemon for linux. So I just ran

sudo apt-get install vsftpd

And that is it. I’m done.

I tested using fireftp on my other machine and it connects via ftp to the server. Now, this setup is just for an in-house server. If you plan on opening your ftp server to the outside world, you should read more about the matter, and read the man pages for vsftpd.

Also take a look at the configuration file located on /etc/vsftpd.conf

Some links that might be useful:

http://blog.dhavalparikh.co.in/2009/11/setting-up-ftp-or-sftp-server-using-vsftpd-on-ubuntu/
http://ubuntuforums.org/showthread.php?t=91887
https://duckduckgo.com/?q=ftp+server+linux
This last link is just a search results list. One one of those result previews is where I read that vsftpd is the default ftp daemon on linux, but the link, which points to http://www.scribd.com/doc/26706992/FTP-Server-in-Linux is unreadable.