Report this

What is the reason for this report?

How To Set Up vsftpd on CentOS 6

Published on June 20, 2012
How To Set Up vsftpd on CentOS 6

Status: Deprecated

This article covers a version of CentOS that is no longer supported. If you are currently operating a server running CentOS 6, we highly recommend upgrading or migrating to a supported version of CentOS.

Reason: CentOS 6 reached end of life (EOL) on November 30th, 2020 and no longer receives security patches or updates. For this reason, this guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other CentOS releases. If available, we strongly recommend using a guide written for the version of CentOS you are using.

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 yum install vsftpd

We also need to install the FTP client, so that we can connect to an FTP server:

sudo yum install ftp

Once the files finish downloading, vsftpd will be on your VPS. Generally speaking, the virtual private server is already configured with a reasonable amount of security. However, it does provide access to anonymous users.

Step Two—Configure VSFTP

Once VSFTP is installed, you can adjust the configuration.

Open up the configuration file:

sudo vi /etc/vsftpd/vsftpd.conf

One primary change you need to make is to change the Anonymous_enable to No:

anonymous_enable=NO

Prior to this change, vsftpd allowed anonymous, unidentified users to access the VPS'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.

local_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

Finish up by restarting vsftpd:

sudo service vsftpd restart

In order to ensure that vsftpd runs at boot, run chkconfig:

chkconfig vsftpd on

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 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

Etel Sverdlov
Etel Sverdlov
Author
See author profile

Former Director of Community at DigitalOcean. Expert in cloud topics including LAMP Stack, CentOS, Ubuntu, MySQL, SSL certificates, and more.

Still looking for an answer?

Was this helpful?
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!

You may want to add “chkconfig vsftpd on” to the end, otherwise when the server/VPS is rebooted, no user will be able to log-in until vsftpd is started from CLI.

Thanks for the addition—I have updated the article to include chkconfig!

Nice Tutorial! But please add how to setup users and their default path or directory of access.

Hi Sudsachin, that’s a great suggestion! I will build out the article further in the coming days. Thanks!

Etel,

I’m really liking digital ocean tutorials.

I was hoping you could create a tutorial on how to install virtualization and get it started via CentOS 6.3

  1. Tried KVM - I can’t figure out how to get the connections to bridge so that I can access the world outside my VPS I created.
  2. Tried LXC - Couldn’t get it to work 3.Tried Xen - The only kernels I can find do not seem to work with CentOS6.3

Can you save me? :)

If you are running virtualization inside of a virtual server from DigitalOcean you will most likely not be able to bridge the connection because the server is already virtualized and running through the hypervisor.

Or is this on a dedicated system.

This is on a dedicated server… I only came across this place via google.

You should be able to get a dedicated server to be setup as a hypervisor with KVM installed on it - however the networking bridge can also be affected on your network setup from the switch that your server is connected to.

Best thing to do is contact your dedicated server provider and see if they can provide you a bit of guidance in getting this setup.

what will be the ftp username and password for this setup?

It will be your existing server user

When add a new user:

adduser userftp

passwd userftp

You can disable the login ssh with and just for ftp:

usermod -s /sbin/nologin userftp

Regarsd

Thanks Etel and Gildus, Now I already created an ftp login and I was able to successfully login using filezilla, but I cannot upload files beacause I do not see var/www/html folder

That sounds like a user path issue, what you could do is upload a file like: test_file

Then login to the system as root and see where that file is located: find / -name test_file

Then you will see where that user is logging in if it’s not displayed when you issue the PWD command inside of FTP and you can review your user’s home directory accordingly.

Just signed up after a year with another cloud provider. Going to miss their support, but their cloud options are just not performing the way we need them to. Problem now is I have to set up this server and man I’m having issues. Would be a great start to learn how to set up users and passwords jailed to a directory. My goal right now is to get a test installation of Wordpress to update plugins via ftp, but not working. Final goal is to run Magento using Nginx here on DO.

Easiest way to do jailing is to restrict SSH access for all new users so that they only have FTP access, you can do that by modifying their “shell” to something like /sbin/nologin.

Then move forward step by step from there.

Ok I am really loving these articles. Concise, to the point and they work. This article is a great example. Yes I have installed FTP servers and VSFTPD before. However these articles point me in the right direction and help me avoid previous pitfalls. Last time VSFTPD was a schlepp. This time a breeze!

rock on

Thank you, Ed! Thank you so much for your kind comment! It’s really appreciated =]

Thank you very nice tutorial, got running in 10 mins!

Thanks alot! But its work only with SFTP connection

I agree these articles are great. However, I am not able to connect via FTP after following these instructions.

Opps, I stand corrected SFTP is working. Thank you.

@ sudsachin on the last line just add

local_root=public_html

Thank you for this tutorial. I’m not quite understanding how to have the sftp login have a unique password separate from SSH? Any step by step clarification? I’d appreciate it!

Another question is how to give SFTP a specific port number? in conjunction with iptables?

Wish I could edit my posts so I wouldn’t be triple posting… but anyway some things to add I found from this article: http://king-tutor.com/index.php/centos-6-3/24-install-and-configure-vsftp-on-centos-6-3 configure iptables /etc/sysconfig/iptables: -A INPUT -m state --state NEW -p tcp --dport 21 -j ACCEPT Ensure that the space-separated list of modules contains the FTP connection-tracking module /etc/sysconfig/iptables-config IPTABLES_MODULES=“ip_conntrack_ftp”

Ty Etel :D

Here, to send files using nginx, i need set local_root

TYPE: vi /etc/vsftpd/vsftpd.conf

WRITE: local_root=/usr/share/nginx/html

TYPE: sudo chown -R YOUR_FTP_USER_HERE /usr/share/nginx/html

Hello,

I have system with Centos 6.3 loaded on it and I want to convert it into a server that can be accessed over the internet and also shared with friends and family with read access. This is my very first time using linux so could you please help me out? I played around a bit with owncloud with no success hence just loaded the Centos OS once again to start afresh. FYI I do not have a domain name registered in my name. I have a internet connection that does not provide static ip.

Thanks, AVG.

Hi ,

login to ftp with server username and password. But the default folder it gives access is to /home/<user>. How can i set the default folder to var/www/html folder

Thanks Kiran

Nice article…It works perfect…Thanks a lot

@David Levy SFTP authenticated using SSH, so you can’t have different passwords. To change the port, edit the Port 22 line in /etc/ssh/sshd_config and restart ssh.

@kiran Please see muriloreinert’s comment above.

@muriloreinert Thanks. It works.

When trying to execute “chkconfig vsftpd on”, I get this message: You do not have enough privileges to perform this operation.

Do you know what is happening ?

@siatg you must follow this tutorial as root (you can also run “sudo -s” as an account with sudo privileges).

I followed the instructions and succesfully setup the ftp, now i want to login, i guess i have to create a user…how?

@complementaryart you can add a user by running the following command: “sudo adduser yourusernamehere”

To get FTP access to /var/www/html folder use the root user as the ftp user

  1. assign a password to the root user -> passwd root
  2. sudo nano /etc/vsftpd/user_list and comment on root
  3. sudo nano /etc/vsftpd/ftpusers and comment on root again
  4. sudo nano /etc/vsftpd/vsftpd.conf and write at the end local_root=/var/www/html there might be some security issues at using the root user as ftp but it did the trick for me.

I also thought about using aliases as explained here http://httpd.apache.org/docs/2.2/urlmapping.html but I cant figure out how to define them.

Other suggestions on a better approach will be most welcome!

The @muriloreinert comments doesn’t work for me. I can login only with one of my VPS users, but in the /home folder. What’s the steps I need do to all my VPS users access the /var/www/html folder?

@eughenio Move all the files from /var/www/html to your user’s home directory and symlink it so Apache/nginx can still access it:

mv /var/www/html /home/youruser/html ln -s /var/www/html /home/youruser/html

It does not work for me except to allow access from the command line

It won’t work with FireFTP or in the browser

This tutorial needs to be updated

To check if the iptables are what’s not causing you to connect you can shut it down

service iptables stop

then try your connection, to restart it later…

service iptables start

To open ports in iptables type the following command from the command prompt

iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

Then type:

service iptables save

Then type:

service iptables restart

You can do the same as above except change the port number to port 21

to check the file to see what ports are open use:

cat /etc/sysconfig/iptables

I’ve personally tried everything and I can’t connect via FTP

I changed the conf file to allow anonymous connections, then tried to login with my FTP client (fire FTP) as anonymous

I also shutdown iptables service and it still won’t let me connect

Anyone have any ideas what’s going on? I’m able to access the server, I can visit my site and it shows the Apache test page so I know it’s working and accessible. I’m also using the same FTP Client (fire FTP) to connect to a different server and it works. So I know it’s nothing blocking my connections on my end.

***************I finally got it working!

Here’s what I did, I switched to FileZilla FTP Clinet in windows instead of FireFTP, since it shows what errors it’s getting. When I saw there was a naming problem I used the ip address of my server (192.111.111.111) instead of the actual web address (mysite.com)

FileZilla connected via SFTP on port 22 which I opened with the above. I hope this helps others.

@SaM5246: Glad you got it working! If you plan on using SFTP, I recommend closing down the FTP port/removing vsftpd.

I’ve changed the chroot_local_user to NO and enter the values at the end of file: local_root=/var/www/html file_open_mode=0755 chmod_enable=YES

I can access the FTP and access with different users.

The problem now is, I can’t overwrite an file, the FTP says I’m not allowed… If I change the chmod of file to 777 it let me overwrite the file, in another case I receive the message: 553 Could not create file. Error: Critical file transfer error

How can I fix it???

@eughenio: Make sure the user you’re connecting as has write permission to /var/www/html:

chmod -R youruser:youruser /var/www/html

@Kamal Nasser, I tried, but I received: chmod: invalid mode: USER:USER' Try chmod --help’ for more information.

Sorry, my bad. It should be ‘chown’, not ‘chmod’.

Thank you!

I couldn’t get these instructions to work with FTP. But could with SFTP. I think it may be worth changing your tutorial to accommodate this. Thanks

Creative CommonsThis work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.
Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

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.