I have gone through quite a few setup guides but couldn't figure out, how to configure VSFTPD for LAN-only access, and restrict the access to a single directory (e.g.: ~/Downloads).
If possible, I do not even want to expose its presence to the Internet. Any help is greatly appreciated.
PC: Ubuntu Mate 19.04 64-bit.
LAN-Only Access
This is best done with firewall rules. We will use
ufw
the uncomplicated firewall for this.First we check the status of
ufw
If you see
Status: inactive
then use the following command to enableufw
:As described in the link below we will allow ports 20 and 21 for the basic VSFTPD access. We will not use the simple ufw rule like:
as this will allow access from everywhere. To allow LAN-Only access we will use advance syntax:
The
from 192.168.0.0/24
is the LAN-Only part. Yours may be different. Some home routers assign IP addresses in the range 192.168.0.x, and others in the range 192.168.1.x, where x is between 2-255. The/24
subnet mask says any value of x in that range is allowed.The
to any
means any IP address assigned to this computer is okay. Since this computer is not acting as a router, this setting is okay.The
port 20
(or21
) is the port this rule opens.The
proto tcp
is the onlytcp
protocol (not theudp
protocol) can be used.If we want to add the ports 990, and 40,000 to 50,000 ports to the firewall as in the tutorial below, we can use one command to do that:
A Note about IPv6
I don't know enough about IPv6 local addresses and subnet masks to write an answer that includes IPv6 ufw rules. Without any Ipv6 allow rules any attempt to use IPv6 addresses to access the
ftp
site will be denied.The answers to this question suggests there may not be an easy solution for IPv6: How do I allow local IPv6 subnets in ufw?
For what it is worth, the following allow rule syntax (based on an answer to the above question) is accepted by
ufw
:This should allow ftp access from the link-local IPv6 range that start with
fe80
.Restrict user to a single directory
This is very well described in the Digital Ocean Tutorial. The main steps are reproduced below:
In this example the username is
sammy
. The basic concept is the usersammy
must not have write access to the base directory of the user-accessible directory. Create theftp
folder, set its ownership, and be sure to remove write permissions with the following commands:Next, we create the directory where files can be uploaded and assign ownership to the user:
Next we edit the VSFTPD configuration file in nano:
and make the following changes / additions:
When we are done making the change, save and exit the file.
Then, we create and add our user to the file. We’ll use the -a flag to append to file:
Funally we restart the daemon to load the configuration changes:
Hope this helps