Install vsftpd (ftp) server on raspberry pi
Installation
First things first, we need to install the vsftpd package.
1 2 3 |
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.
1 2 3 |
sudo nano /etc/vsftpd.conf |
For anonymous login
you have to change only the default folder location. I use a usb hard drive with my pi, so I need to target a folder inside it. If the folder is named ftp and the usb hdff named exthdd, add the following line at the end:
1 2 3 |
anon_root=/media/exthdd/ftp |
Save & restart with .
1 2 3 |
sudo service vsftpd restart |
To go further with login credentials..
we want to change or uncomment the following values.
1 2 3 4 5 6 7 8 9 |
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 |
Also, add a line to the bottom of the file:
1 2 3 |
force_dot_files=YES |
Then hold the Ctrl key and press “x”, then “y”, then the Return / Enter key.
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.
1 2 3 4 5 |
mkdir /home//ftp mkdir /home//ftp/files chmod a-w /home//ftp |
Now you should be able to connect to your from any FTP client and start uploading/downloading files
Troubleshooting
If you came across problems..
At the moment you will need to change the directory every time you login by FTP, to solve this:
Type:
1 2 3 4 |
sudo -i passwd root |
Type in any password (this is only temporary)
1 2 3 4 |
exit exit |
Start a new SSH session
1 2 3 4 5 |
Username: root Password (the one you just set) "nano /etc/passwd" |
find the line
1 2 3 |
pi:x;1000:1000:Raspberry Pi User,,,:home/pi:/bin/bash |
and change it to
1 2 3 |
#pi:x;1000:1000:Raspberry Pi User,,,:home/pi:/bin/bash |
Then hold the Ctrl key and press “x”, then release Ctrl and press “y” then hit Return / Enter.
1 2 3 |
usermod -d /var/www pi |
Now close the SSH session, and start a new one with username: pi and your password, and type the following:
1 2 3 4 5 |
sudo -i usermod -L root exit |
Now you are able to connect to your Raspberry Pi with an FTP client, using the following information:
Host: (Hostname you set – I used raspberryPi)
Username: pi
Password: (Password you set previously)
Port: 21