Tutorial

How To Set Up vsftpd on Ubuntu 12.04

Published on June 20, 2012
How To Set Up vsftpd on Ubuntu 12.04

Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.

About vsftpd

Warning: FTP is inherently insecure. If you must use FTP, consider securing your FTP connection with SSL/TLS. Otherwise, it is best to use SFTP, a secure alternative to FTP.

The first two letters of vsftpd stand for "very secure" and the program was built to have strongest protection against possible FTP vulnerabilities.

Step One—Install vsftpd

You can quickly install vsftpd on your virtual private server in the command line:

sudo apt-get install vsftpd

Once the file finishes downloading, the VSFTP will be on your droplet. Generally speaking, it is already configured with a reasonable amount of security. However, it does provide access on your VPS to anonymous users.

Step Two—Configure vsftpd

Once vsftpd is installed, you can adjust the configuration.

Open up the configuration file:

sudo nano /etc/vsftpd.conf

The biggest change you need to make is to switch the Anonymous_enable from YES to NO:

anonymous_enable=NO

Prior to this change, vsftpd allowed anonymous, unidentified users to access the server's files. This is useful if you are seeking to distribute information widely, but may be considered a serious security issue in most other cases.

After that, uncomment the local_enable option, changing it to yes and, additionally, allow the user to write to the directory.

local_enable=YES
write_enable=YES

Finish up by uncommenting command to chroot_local_user. When this line is set to Yes, all the local users will be jailed within their chroot and will be denied access to any other part of the server.

chroot_local_user=YES

Save and Exit that file.

Because of a recent vsftpd upgrade, vsftpd is "refusing to run with writable root inside chroot". A handy way to address this issue to is to take the following steps:

  1. Create a new directory within the user's home directory
  2. mkdir /home/username/files
  3. Change the ownership of that file to root
  4. chown root:root /home/username
  5. Make all necessary changes within the "files" subdirectory

Then, as always, restart:

 sudo service vsftpd restart

Step Three—Access the FTP server

Once you have installed the FTP server and configured it to your liking, you can now access it.

You can reach an FTP server in the browser by typing the domain name into the address bar and logging in with the appropriate ID. Keep in mind, you will only be able to access the user's home directory.

ftp://example.com

Alternatively, you can reach the FTP server on your virtual server through the command line by typing:

 ftp example.com

Then you can use the word, "exit," to get out of the FTP shell.

By Etel Sverdlov

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the author(s)

Etel Sverdlov
Etel Sverdlov
See author profile
Category:
Tutorial

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
40 Comments
Leave a comment...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

I still can’t make directory or file under /home/username, how to fix it?

Thx

I am sure you might have found solution for this by now. But for those having same challenge, you can use the sudo keyword before using the mkdir file_name like so:

sudo mkdir file_name
Moisey Uretsky
DigitalOcean Employee
DigitalOcean Employee badge
July 28, 2012

You will want to create a sub-directly inside of /home/username/sub-directory which is owned by username and upload your files there.

We’ll also review this documentation and clean it up a bit to make it easier for future installs.

Thanks.

I had to make each directory individually. (i.e. mkdir /username then mkdir /files, etc.

Moisey Uretsky
DigitalOcean Employee
DigitalOcean Employee badge
August 20, 2012

If you want to create a multi-directory path that doesnt exist you can add the -p flag to the mkdir command:

mkdir -p /home/username/files

good

good

How can I set the username and password for the FTP account?

Moisey Uretsky
DigitalOcean Employee
DigitalOcean Employee badge
September 7, 2012

adduser username

To create a new user. =]

Hi there, I posted this question above, but from where do I create the FTP username? From the root? From the user I have to login ssh?

write_enable=TRUE

Hello I just setup a Virual Host on my VPS, I have it set were there web file are in /home/user/public_html

It lets me log in and see the public_html but when I try to upload a file it uploads it but does not show up in the public_html. How can I fix this issues?

Thanks

i setup vsftp, how i setup a new subdomain in ‘/var/static1’, with it own ftp user and password, that can not acces to the rest of directory server

Hi, I was able to follow all the steps but when I try to move ownership of /home/demo/files using chown I get Operation not permitted but when I used the sudo command that seemed to resolve it. However when I try to connect to the ftp site using FileZilla i get vsftp refusing to run with writable root inside chroot()

@jamie.m.garner: It sounds like you took the chown root:root off the /home/demo folder Run that command again: chown root:root /home/demo… and then to give correct access to the files command use chown -R demo /home/demo/files

Etel Sverdlov
DigitalOcean Employee
DigitalOcean Employee badge
December 4, 2012

jhawk, make sure you are in the correct directory when you are uploading the files. I am assuming you are using a FTP client like filezilla. When you are in that program, make sure that you drag the files to the correct folder from your computer.

pescadito, set your user’s home directory to /var/static1, ensuring that the directory is owned by root. The process is explained in the tutorial above in Step2

Hello, whenever I try to use the ‘chown root:root /home/“my username”’, I get a message saying the operation is not permitted. Unless I need to be logged in as the root to transfer the ownership rules. Please tell me a fix?

I fixed my earlier problem, but now when i log into the ftp server, i am restricted to the root and can’t make anymore folders such as “public_html” for my files. I’ve user mkdir and doesn’t work. Any help?

Moisey Uretsky
DigitalOcean Employee
DigitalOcean Employee badge
December 21, 2012

You can only change ownership to root:root as the root user.

Root can change permissions for any other users.

You should instead change the ownership of the directory to : chown username /home/username

The way you did it currently it would be owned by root so no one other than the root user would be able to create directories, write files, etc.

I also had to uncomment write_enable=YES to upload.

Having an issue with vsftpd allowing me to authenticate in that it claims my pw is not correct. However, a general note for this and perhaps other docs. Put in the command(s) necessary to uninstall the package.

Moisey Uretsky
DigitalOcean Employee
DigitalOcean Employee badge
January 14, 2013

You can also check the error log to see if there is any additional information provided. Whether its an auth failure or if it’s perhaps something to do with permissions or configuration.

I setup as the tutorial suggested but seem to be having connection problems. First I will state that I have mad a couple of alterations. I uncommented write_enable=YES and added user_subtoken=$USER & local_root=/home/$USER/files to attempt to jail the user into the files folder in their home directory. This seems to cause some sort of conflict throwing the error “500 OOPS: vsftpd: refusing to run with writable root inside chroot()” I’m hoping you can shed some light on this. Thanks

I’ve always used this tutorial: http://www.noob2geek.com/linux/setup-vsftpd-debian-ubuntu/

the only thing you need to add is:

‘sudo chmod a-w /var/www/your_ftp_directory’

‘sudo mkdir /var/www/your_ftp_directory/new_directory’

to get 'round the ‘error "500 OOPS: vsftpd: refusing to run with writable root inside chroot()’ error.

Hope this helps…

very poor explanation… Which domain you refer to?? Is it the IP adress emailed in the droplet creation??

Etel Sverdlov
DigitalOcean Employee
DigitalOcean Employee badge
February 5, 2013

It is the IP emailed to you; or, if you site a set up on that droplet, it would be the domain name for it.

For all the people who want to allow external folders to be available in your ftp, here is a quick tip:

mkdir /home/username/www mount --bind /var/www/path/to/your/folder/ /home/username/www sudo nano /etc/fstab

-and add the following line in the file and save /var/www/path/to/your/folder /home/username/www none bind 0 0

-restart sudo service vsftpd restart

-now you will be able to access /var/www/path/to/your/folder in your ftp.

Hope this helps alot of people out there!

I had vsftpd up and running when I first started my droplet. When I decided to start my droplet over I can not get vsftpd to work. When I try to connect with Transmit or Filezilla I get the following error

“Error -203: miscellaneous error occurred while trying to login to the host”

Any idea how to trouble shoot this?

Hi

I’ve followed the tutorial, yet appear to have permission problems. When I try to create a new theme folder via Filezilla in wp-content/themes I get the error message: “550 permission denied. Critical file transfer error”

I also can’t delete files and puzzlingly when I install a theme via wordpress it doesn’t show up in the FTP file tree. Any ideas?

Cheers

Hey grozanc,

Log in as root, create the folder you want to access via ftp (in your home folder).

Then ‘chown root:root /home/youruser’.

This will fix the issue. It’s like mentioned in the article, the new vsftpd does not let you log in with ‘writable root inside chroot’, which, if you check transmit’s log file, is what’s happening.

That aside, here’s a question for the other members: Since we are limited to ftp user’s home directory, is it wise to move my www folder there as I want to run my droplet as a web server? I’m guessing I will also have to change the ServerRoot variable in Apache to point to my ftpuser’s www folder?

Thanks and good job DO for providing such an affordable hosting solution.

So how exactly do I access /var/www/ in FTP ? I can only see the /files/ folder I have created using this tutorial…

I followed this article, and everything was OK, but… :) I can connect via FTP to the logged user home, but I can’t manage files: 550 Rename failed 550 Create directory operation failed 553 Could not create file 550 SITE CHMOD command failed

This is my vsftpd config: local_enable=YES write_enable=YES local_umask=022 chroot_local_user=YES

I created a new user webmaster to connect via ftp to /var/www path. root@dropplet:/var# id webmaster uid=1000(webmaster) gid=33(www-data) groups=33(www-data)

root@dropplet:/var# groups webmaster webmaster : www-data

root@dropplet:/var# ls drwxr-xr-x 2 www-data www-data 4096 Feb 27 23:20 www/

So my user belongs to www-data group, and www-data owns /var/www /var/www is 755

I can’t understand why I cannot manage files via ftp with a user who belongs the owner group.

I tried with proftpd with the same results, so it must be a permissions problem :s

Any idea? Thank you!

"#adduser username

To create a new user. =]"

Can you explain this in details? Thanks!

Well I created a user but still cannot log in…

Hi, I have done all that you mentioned in this document, but when i try to login from filezilla using my root user and password that was emailed to me, I get the error Response: 530 Login incorrect. Error: Critical error Error: Could not connect to server Please help

A tip for those one that can upload files via FTP but the uploaded files permissions are set to rw-/—/— and then the pages are not executed by the browser:

You can uncomment the line local_umask=022 in the vsftpd.conf file

More info here: http://www.bluehostforum.com/showthread.php?11422-FTP-default-file-permissions

I just setup a new droplet with ubuntu 12.10 32bit. I followed the guide to install apache2, mysql, php and vsftpd. I created a new user ftp2www whose home is /var/www to be able to ftp-upload data to the www root. But I can’t do this because FileZilla tells me I am not allowed to.

Error Message: 500 OOPS: vsftpd: refusing to run with writable root inside chroot()

A bit of googling ( http://askubuntu.com/questions/239239/ubuntu-12-04-500-oops-vsftpd-refusing-to-run-with-writable-root-inside-chroot ) tells me to add allow_writeable_chroot=YES to /etc/vsftpd.conf but when i restart my vsftpd it doesn’t start but hangs in pre-start.

If i remove allow_writeable_chroot=YES from the conf it starts up fine, but then again… i can’t use my ftp2www user whose home is /var/www .

After following the tutorial and then trying to use FileZilla to copy a file to the home/username/files directory, I was getting this error: open for write:

permission denied Error: File transfer failed

I got this working by executing: chown username home/username/files

After executing that I was able to copy a test file to the files folder.

Does anybody really need ftp? I’ve been with a few hosting companies that outright disallowed ftp.

For most file transfer you can just use sftp, which will go over ssh. I’m guessing a lot of people are installing ftp thinking they need it because it appears in the list of tutorials. It might be good to include a suggestion to sftp if suitable at the beginning.

When I did the install, mostly out of curiosity, I found the instructions a bit confusing due to references to “file” when the command refers to the users home directory - “then change the ownership of that file to root” followed by: “chown root:root /home/username”

But this isn’t a file- it’s users home directory. And we didn’t create a file, but rather a directory. And why root? I imagine a lot of people are doing:

chown root:root /home/username/files

Or assuming the user in the instructions was root.

Finally, I have absolutely no clue what the original error means or how this fixes it. I’m rather curious.

Thanks, Nick

To see what permissions you have already set for any directory

sudo ls -la /var/www/

Replace “/var/www/” with the directory you need to check!

i have a user, but can’t login! 530 Login Incorrect

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.