原文出自官方网站
This example shows how to extend the "VIRTUAL_USERS" example to reflect
a slightly more complex setup. Let's assume that we want two types of virtual user - one that can only browse
and download content, and another that can upload new content as well as
download existing content. To achieve this setup, we can use use of vsftpd's powerful per-user
configurability (new in v1.1.0). In the previous virtual user example, we created two users - tom and fred.
Let's say that we want fred to have write access to upload new files whilst
tom can only download. Step 1) Activate per-user configurability. To activate this powerful vsftpd feature, add the following to
/etc/vsftpd.conf:
user_config_dir=/etc/vsftpd_user_conf And, create this directory: mkdir /etc/vsftpd_user_conf
Step 2) Give tom the ability to read all files / directories. At the end of the last example, we noted that the virtual users can only
see world-readable files and directories. We could make the /home/ftpsite
directory world readable, and upload files with world-read permission. But
another way of doing this is giving tom the ability to download files which
are not world-readable. For the tom user, supply a config setting override for
anon_world_readable_only: echo "anon_world_readable_only=NO" > /etc/vsftpd_user_conf/tom Check it out - login as tom and now "ls" will return a directory listing!
Log in as fred and it won't.
NOTE - restart vsftpd to pick up the config setting changes to
/etc/vsftpd.conf. (Advanced users can send SIGHUP to the vsftpd listener
process).
Step 3) Give fred the ability to read all files / directories and create
new ones but not interfere with existing files. echo "anon_world_readable_only=NO" > /etc/vsftpd_user_conf/fred
echo "write_enable=YES" >> /etc/vsftpd_user_conf/fred
echo "anon_upload_enable=YES" >> /etc/vsftpd_user_conf/fred Check it out - login as tom and you can't upload. Log in as fred and you can!
Try and delete a file as both tom and fred - you can't.
3.PER_IP_CONFIG
his example should quickly show you the possibilites of per-IP configuration
with vsftpd's tcp_wrappers integration. This is new with v1.1.3. To use this, you need vsftpd built with tcp_wrappers! This is accomplished
by editing "builddefs.h" and changing #undef VSF_BUILD_TCPWRAPPERS
to
#define VSF_BUILD_TCPWRAPPERS And then rebuild. If you are lucky your vendor will have shipped the vsftpd
binary with this already done for you. Next, to enable tcp_wrappers integration, you need this in your vsftpd.conf: tcp_wrappers=YES And you'll need a tcp_wrappers config file. An example one is supplied in this
directory: hosts.allow. It lives at /etc/hosts.allow. Let's have a look at the example: vsftpd: 192.168.1.3: setenv VSFTPD_LOAD_CONF /etc/vsftpd_tcp_wrap.conf
vsftpd: 192.168.1.4: DENY The first line:
If a client connects from 192.168.1.3, then vsftpd will apply the vsftpd
config file /etc/vsftpd_tcp_wrap.conf to the session! These settings are
applied ON TOP of the default vsftpd.conf.
This is obviously very powerful. You might use this to apply different
access restrictions for some IPs (e.g. the ability to upload).
Or you could give certain classes of IPs the ability to skip connection
limits (max_clients=0).
Or you could increase / decrease the bandwidth limiter for certain classes
of IPs.
You get the point :-) The second line:
Denies the ability of 192.168.1.4 to connect. Very useful to take care of
troublemakers. And now you don't need xinetd to do it - hurrah.
4.INTERNET_SITE_NOINETD
This example shows how to run vsftpd in "standalone" mode - i.e. without
needing to run an inetd of some kind (inetd, xinetd, tcpserver etc). vsftpd has supported standalone mode since v1.1.0. With the release of v1.1.3, the feature list of standalone mode has grown so
that large internet sites no longer need to use an inetd.
Previously, large internet sites were forced to use xinetd for the important
feature of "limit number of concurrent connections from a single IP address".
Unfortunately, there seem to be xinetd stability issues - various larger
sites are reporting that xinetd's session counting can go wrong and incorrectly
kick off users because it thinks the FTP site is full when it is not. vsftpd now natively handles maximum session counts and maximum session per IP
counts. It can also do native access control via tcp_wrappers integration and
even per-connect-IP configurability. To use this example config: 1) Copy the vsftpd.conf file in this directory to /etc/vsftpd.conf. 2) Start up vsftpd, e.g.
vsftpd & 3) That should be it! The example vsftpd.conf is based on the vsftpd.conf from the INTERNET_SITE
example. Let's look at the differences (at the top): # Standalone mode
listen=YES This tells vsftpd to run in standalone mode. Do NOT try and run vsftpd from
an inetd with this option set - it won't work, you may well get 500 OOPS:
could not bind listening socket. max_clients=200
max_per_ip=4 The maximum number of session is 200 (new clients will get refused with a
busy message). The maximum number of sessions from a single IP is 4 (the
5th connect will get refused with a suitable message).
One further note on standalone mode, regarding virtual IPs. This is very
easy - just run one copy of vsftpd per virtual IP (remembering to give each
a separate config file on the command line).
Distinguish which vsftpd is for which virtual IP with a setting like this
in the vsftpd.conf: listen_address=192.168.1.2 And launch vsftpd with a specific config file like this:
vsftpd /etc/vsftpd.conf.site1 &
# Standalone mode
listen=YES
max_clients=200
max_per_ip=4
# Access rights
anonymous_enable=YES
local_enable=NO
write_enable=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
# Security
anon_world_readable_only=YES
connect_from_port_20=YES
hide_ids=YES
pasv_min_port=50000
pasv_max_port=60000
# Features
xferlog_enable=YES
ls_recurse_enable=NO
ascii_download_enable=NO
async_abor_enable=YES
# Performance
one_process_model=YES
idle_session_timeout=120
data_connection_timeout=300
accept_timeout=60
connect_timeout=60
anon_max_rate=50000
5.INTERNET_SITE
This example shows how you might set up a (possibly large) internet facing
FTP site. The emphasis will be on security and performance. We will see how by integrating vsftpd with xinetd, we get a powerful
combination. Step 1) Set up your xinetd configuration file. An example xinetd configuration file "vsftpd.xinetd" is supplied.
To install it: cp vsftpd.xinetd /etc/xinetd.d/vsftpd Let's look at the important content in this file and see what it does: disable = no
socket_type = stream
wait = no This says that the service is active, and it is using standard TCP sockets. user = root
server = /usr/local/sbin/vsftpd The server program /usr/local/sbin/vsftpd is used to handle incoming FTP
requests, and the program is started as root (vsftpd will of course quickly
drop as much privilege as possible). NOTE! Make sure that you have the vsftpd
binary installed in /usr/local/sbin (or change the file path in the xinetd
file). per_source = 5
instances = 200 For security, the maximum allowed connections from a single IP address is 5.
The total maximum concurrent connections is 200. no_access = 192.168.1.3 As an example of how to ban certain sites from connecting, 192.168.1.3 will
be denied access. banner_fail = /etc/vsftpd.busy_banner This is the file to display to users if the connection is refused for whatever
reason (too many users, IP banned). Example of how to populate it:
echo "421 Server busy, please try later." > /etc/vsftpd.busy_banner log_on_success += PID HOST DURATION
log_on_failure += HOST This will log the IP address of all connection attempts - successful or not,
along with the time. If an FTP server is launched for the connection, it's
process ID and usage duration will be logged too. If you are using RedHat
like me, this log information will appear in /var/log/secure.
Step 2) Set up your vsftpd configuration file. An example file is supplied. Install it like this: cp vsftpd.conf /etc Let's example the contents of the file: # Access rights
anonymous_enable=YES
local_enable=NO
write_enable=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO This makes sure the FTP server is in anonymous-only mode and that all write
and upload permissions are disabled. Note that most of these settings are
the same as the default values anyway - but where security is concerned, it
is good to be clear. # Security
anon_world_readable_only=YES
connect_from_port_20=YES
hide_ids=YES
pasv_min_port=50000
pasv_max_port=60000 These settings, in order
- Make sure only world-readable files and directories are served.
- Originates FTP port connections from a secure port - so users on the FTP
server cannot try and fake file content.
- Hide the FTP server user IDs and just display "ftp" in directory listings.
This is also a performance boost.
- Set a 50000-60000 port range for passive connections - may enable easier
firewall setup! # Features
xferlog_enable=YES
ls_recurse_enable=NO
ascii_download_enable=NO
async_abor_enable=YES In order,
- Enables recording of transfer stats to /var/log/vsftpd.log
- Disables "ls -R", to prevent it being used as a DoS attack. Note - sites
wanting to be copied via the "mirror" program might need to enable this.
- Disables downloading in ASCII mode, to prevent it being used as a DoS
attack (ASCII downloads are CPU heavy).
- Enables older FTP clients to cancel in-progress transfers. # Performance
one_process_model=YES
idle_session_timeout=120
data_connection_timeout=300
accept_timeout=60
connect_timeout=60
anon_max_rate=50000 In order,
- Activates a faster "one process per connection" model. Note! To maintain
security, this feature is only available on systems with capabilities - e.g.
Linux kernel 2.4.
- Boots off idle users after 2 minutes.
- Boots off idle downloads after 5 minutes.
- Boots off hung passive connects after 1 minute.
- Boots off hung active connects after 1 minute.
- Limits a single client to ~50kbytes / sec download speed.
Step 3) Restart xinetd. (on RedHat)
/etc/rc.d/init.d/xinetd restart If you run into problems, check:
1) Your /etc/xinetd.d directory only has one FTP service.
阅读(2286) | 评论(0) | 转发(0) |