How to setup an FTP server with vsftpd on Raspberry Pi

Want to setup an FTP server on Raspberry Pi? It’s actually fairly simple. For this tutorial we’ll assume that you’re using a fresh install of Raspbian.

First things first, we need to install the vsftpd package.

sudo apt-get install vsftpd

By default vsftpd is configured for anonymous access with read-only permissions. We’re going to change things so that it requires you to authenticate with a local user. Let’s open the configuration file.

sudo nano /etc/vsftpd.conf

We want to change or uncomment the following values.

anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
chroot_local_user=YES
user_sub_token=$USER
local_root=/home/$USER/ftp

After that restart the vsftpd service. Now we need to create a couple folders in your local user’s home folder. The ftp folder will be the root when you connect. The way vsftpd works, the root is not allowed to have write permissions on it, so we’ll create a sub-folder inside the root called files which our local user will be allowed to write to. This is where you’d upload/download files from with an FTP client.

mkdir /home//ftp
mkdir /home//ftp/files
chmod a-w /home//ftp

Now you should be able to connect to your Raspberry Pi from any FTP client and start uploading/downloading files.

Hungry for more Pi?

For more project ideas be sure to check out our other Raspberry Pi Guides.

  • Guest

    Hi, Thank you so much for the detailed walk through. was able to login to ftp using filezilla ftp client but could not upload any files, as it was saying

    Response: 553 Could not create file.
    Error: Critical file transfer error”

    what could have gone wrong ?

    • http://www.ducky-pond.com/ Ben Hanna

      Make sure that you’re uploading to the ‘files’ folder and not the root when you connect. The write permissions are removed on the root folder because it presents a security issue for vsftpd.

    • wodieskodie

      Hi, I was having similar problems. Eventually I ran

      $ sudo chmod 777 /home//ftp/files

      and it worked.

    • lvv10

      Solved it using:
      sudo chown -R /home//ftp/

  • shywolf91

    Could this be used to access external HDDs while away from home (while on vacation)?

    • http://www.ducky-pond.com/ Ben Hanna

      I don’t see why it couldn’t. You’d probably need to mount the HDD somewhere in the /home//ftp/files folder and make sure they have permissions to write to it. If it’s auto-mounted by default you could create a symlink to it in the same folder alternatively.

  • jo

    anonymous_enable=NO
    NOT
    anonymouse_enable=NO

    Other than that it worked great for me !

    Cheers!

    • http://www.ducky-pond.com/ Ben Hanna

      Whoops, missed that typo. The article has been corrected. Thanks for catching that!

  • Manas

    Hi, can you help me with vsftpd?

    I need ftp access with login names (accounts are sames like system accounts?), but without write permissions.

    Should I change it like that?

    anonymous_enable=NO
    local_enable=YES
    write_enable=NO
    local_umask=022
    chroot_local_user=YES
    user_sub_token=$USER
    local_root=/home/$USER/ftp

    Thanks and have a nice day!

    • http://www.ducky-pond.com/ Ben Hanna

      Yep, setting write_enable=NO should do it.

      • Manas

        And change permissions for home directory.

  • Gheorghe

    hey, thanks for detailed tutorial but i have one problem, when i try to un-comment the values i cant find the last two (“user_sub_token=$USER” and “local_root=/home/$USER/ftp”), what can i do?

    • lvv10

      Just add the two lines if you don’t have them

      • Kunal singh

        I’m facing the same issue. In my file nano /etc/vsftpd.conf. I don’t see

        user_sub_token=$USER
        local_root=/home/$USER/ftp

        Shall I paste these lines to the end of the file?

        Also, Can you suggest something on security of ftp server.
        TIA

  • raj

    thanks for this tutorial but i have one question. how can i use a mounted hdd as my default storage for ftp?

    • Juan C. Rocamonde

      If you mean the place where the binaries are stored, yes you can.
      If you mean the place where the ftp server adds, deletes and modifies your files, I suppose you can specifying the path in the config file, but I think that if you do if following this instructions it won’t work. You shall make use of advanced configurations, for that, check out the documentation or ask a expert of the package.

  • ro

    Hi, thanks for the tutorial, but
    I get this error. Can you help me?
    500 OOPS: vsftpd: refusing to run with writable root inside chroot()

    • Juan C. Rocamonde

      You must make sure you’ve added the line “local_root…..”

  • palaniyappan r

    I want to store the files on raspbeery pi from other devices,These are communicate via ethernet. How to configured on raspberry pi?

  • Henrique

    Worked perfectly. As we say it in my country “Sem espinhas”.
    Thank you very much.

  • BhatMahn

    When making those folders you could do it in one line: mkdir -p /home//ftp/files
    Thanks for this guide by the way! 😀

  • Kunal singh

    I’m facing the same issue. In my file nano /etc/vsftpd.conf. I don’t see

    user_sub_token=$USER
    local_root=/home/$USER/ftp

    Shall I paste these lines to the end of the file?

    Also, Can you suggest something on security of ftp server.
    TIA