ubuntu配置vsftpd

来源:互联网 发布:网络大电影投资合同 编辑:程序博客网 时间:2024/06/06 05:58

1、简介

        VSFTPD表示“非常安全的FTP守护进程”,它是GPL授权的FTP服务器,适用于UNIX系统。它的授权遵循GNU通用公共授权。支持IPv6和SSL。vsftpd支持显式(从2.0.0)和隐式(从2.1.0)的FTPS。在Ubuntu, CentOS, Fedora, NimbleX, Slackware 和 RHEL Linux 等发行版本中,它是默认的FTP服务器。它安全,非常快,而且稳定。VSFTPD是成熟和可信的解决方案,支持虚拟用户使用PAM(可插拔的认证模块)。虚拟用户是可以登录,而实际上不存在于系统的/etc/passwd和/etc/shadow文件中。虚拟用户因此比真实用户更安全,因为非安全帐号只能使用FTP服务器,而不能登录到系统使用其他服务,如SSH或SMTP。


      在2011年7月,发现可以从主站下载的2.3.4版本VSFTPD发生了泄漏。登录到泄漏的vsftpd-2.3.4服务器的用户,可能遇到一个笑脸 :) 符号,并且得到在端口6200上的命令窗口。这不是VSFTPD的一个安全漏洞,而是,有的人上传了不同版本的VSFTPD,里面包含了后门。从那时起,vsftpd的站点移动到了Google App Engine


2、特点

      尽管为了获取速度和安全,vsftpd很小,而很多且复杂的FTP设置仍然可以从vsftpd得到! vsftpd可以处理:

(1)虚拟IP配置

(2)虚拟用户

(3)独立或者进程操作

(4)强大的每用户配置

(5)带宽控制

(6)每个源IP可配置

(7)每个源IP限制

(8)IPv6

(9)通过SSL集成支持加密  ...


3、配置指南和基本安装

(1)下载

目前,最新版本是v3.0.2,或者使用 apt-get安装, 如: apt-get install vsftpd

现在,你可以配置它使用本地用户或者虚拟用户通过ftp进行登录。

(2)禁止匿名用户登录,允许本地用户登录,并赋予写权限:

代码:

# No anonymous login  禁止匿名用户
anonymous_enable=NO 
# Let local users login  让本地用户登录
# If you connect from the internet with local users, you should enable TLS/SSL/FTPS  如果使用本地用户从Intenet连接,需要启用TLS/SSL/FTPS 
local_enable=YES
# Write permissions  写权限
write_enable=YES 


(3)改变用户的根目录

限制或改变用户目录(不是VSFTPD服务),有3种选择。搜索“chroot_local_users”,考虑下列代码之一:

代码:


# 1. All users are jailed by default:  默认限制所有用户
chroot_local_user=YES
chroot_list_enable=NO


# 2. Just some users are jailed:  只显示一部分用户
chroot_local_user=NO
chroot_list_enable=YES
# Create the file /etc/vsftpd.chroot_list with a list of the jailed users.


# 3. Just some users are "free": 只是一部分用户是自由的
chroot_local_user=YES
chroot_list_enable=YES
# Create the file /etc/vsftpd.chroot_list with a list of the "free" users.


(4)拒绝(或允许)某些用户登录

拒绝用户登录,在文件末尾添加选项: 

代码:

userlist_deny = YES


在文件 /etc/vsftpd.denied_users中,添加不能登录的用户的用户名,每个用户名占1行。


(5)仅仅允许某些用户登录:

代码:

userlist_deny=NO
userlist_enable=YES
userlist_file=/etc/vsftpd.allowed_users

在文件/etc/vsftpd.allowed_users中添加能登录用户的用户名。

不允许的用户在输入密码前,就会被提示错误,因此不能登录。


(6)TLS/SSL/FTPS

注意:如果你是从Internet连接到你的服务器,必须确定使用这个,否则密码会以明文传输,等等。

让vsftpd使用加密(更安全),修改或添加下列选项(某些选项不在原始配置文件中,需要添加):

代码:

ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
ssl_tlsv1=YES
ssl_sslv2=YES
ssl_sslv3=YES
# Filezilla uses port 21 if you don't set any port  
# in Servertype "FTPES - FTP over explicit TLS/SSL" 如果你在服务器类型"FTPES - FTP over explicit TLS/SSL"中没有设置任何端口,Filezilla使用端口21。
# Port 990 is the default used for FTPS protocol. 端口990是FTPS协议的默认端口
# Uncomment it if you want/have to use port 990. 如果你想或必须用端口990,去掉注释。
# listen_port=990


如果安装了openssh,就不需要创建一个证书。

在客户端安装Filezilla,使用服务器类型"FTPES - FTP over explicit TLS/SSL“ 选项,以使用TLS/SSL/FTPS连接到你的服务器。


(7)其他选项

# Useful to not write over hidden files:   对不改写隐藏文件有用
force_dot_files=YES


# Hide the info about the owner (user and group) of the files. 隐藏文件拥有者(用户和组)的信息
hide_ids=YES


# Connection limit for each IP:  每个IP连接限制
max_per_ip=2


# Maximum number of clients: 最多客户端数量
max_clients=20


(8)应用新的配置设置

不要忘了应用新的配置,你需要重启vsftpd服务。

代码:

sudo /etc/init.d/vsftpd restart


(9)Webmin模块

使用webadmin的,有个模块 http://www.webmin.com/third.html


(10)设置 pasv_min_port和pasv_max_port以允许外面连接通过防火墙中设置的端口

修改 /etc/vsftpd.conf

代码:

Code: 
pasv_min_port=12000
pasv_max_port=12100


(11)虚拟用户使用TLS/SSL/FTPS和一个公共上传目录 - 复杂的VSFTPD

虚拟用户是不存在于系统的用户 - 他们不在 /etc/passwd中, 在系统中也没有home目录, 不能登录系统除了在vsftpd中 - 如果他们存在,他们可以使用肥系统密码登录vsftpd - 安全。


你可以对不同的虚拟用户做不同的定义,对这些用户赋予不同的权限。如果启用TLS/SSL/FTPS和虚拟用户,你的vsftpd服务器的安全水准就能得到提升:加密的密码,使用的这个密码不能用于系统,而且用户不能直接访问他们的home目录(如果你想的话)。


下面的例子,是从vsftpd站点的虚拟用户示例,文档和随处可见的论坛里的非常好的例子改编而来。目前,有一个约束是启用guest_enable后,本地用户也映射到guest_username。优雅的说法是,如果默认的vsftpd PAM 文件被使用时,系统用户也是guests。为避免混淆,修改使用的PAM文件只认证虚拟用户,让所有的vsftpd用户成为虚拟用户,并按照例子设置他们的密码,主目录和权限。


4、工作间

(1)创建虚拟用户数据库

要创建一个"db4"格式的文件储存用户名(这里另外的选项是apache htpasswd风格的文件,不讨论),首先创建一个普通文本文件,错行写用户名和密码。如,建用户叫做”vivek“,密码是 "vivekpass", "sayali" 密码是 "sayalipass":


# cd /etc/vsftpd
# sudo vi vusers.txt


(2)示例输出:

vivek
vivekpass
sayali
sayalipass

接着,如下创建实际的数据库(可能要求先安装db_util包):


# db_load -T -t hash -f vusers.txt vsftpd-virtual-user.db 
# chmod 600 vsftpd-virtual-user.db
# rm vusers.txt


(3)为虚拟用户配置VSFTPD

编辑vsftpd配置文件(/etc/vsftpd.conf)。添加或修改下面的配置选项,取决于它们是否已经列出在文件中:


anonymous_enable=NO
local_enable=YES
# Virtual users will use the same privileges as local users.虚拟用户将会和本地用户一样使用相同的权限
# It will grant write access to virtual users. Virtual users will use the 会赋予虚拟用户写访问。虚拟用户将和匿名用户使用相同的
# same privileges as anonymous users, which tends to be more restrictive 权限,倾向于更多的约束。
# (especially in terms of write access). (特别是写访问方面)
virtual_use_local_privs=YES
write_enable=YES


# Set the name of the PAM service vsftpd will use 设置vsftpd的PAM服务使用的名字
pam_service_name=vsftpd.virtual


# Activates virtual users  激活虚拟用户
guest_enable=YES


# Automatically generate a home directory for each virtual user, based on a template. 依据模板,自动为每个虚拟用户生成主目录。
# For example, if the home directory of the real user specified via guest_username is 如,如果真实用户的主目录通过guest_username
# /home/virtual/$USER, and user_sub_token is set to $USER, then when virtual user vivek 指定为/home/virtual/$USER,且user_sub_token
# logs in, he will end up (usually chroot()'ed) in the directory /home/virtual/vivek. 设为$USER,则虚拟用户vivek登录时,他会停止在
# This option also takes affect if local_root contains user_sub_token. (通常是chroot())目录/home/virtual/vivek。如果local_root包含

                                                                               user_sub_token,此选项也会生效
user_sub_token=$USER


# Usually this is mapped to Apache virtual hosting docroot, so that 通常这是映射到Apache虚拟主文档根目录,因此用户可以上传文件
# Users can upload files
local_root=/home/vftp/$USER


# Chroot user and lock down to their home dirs  改变用户的主目录,并锁定在他们的主目录
chroot_local_user=YES


# Hide ids from user 隐藏来自用户的ids
hide_ids=YES


保存,关闭文件。


(4)创建使用你新建数据库的PAM文件

下面的PAM用来认证用户,它使用你的新数据库。 创建 /etc/pam.d/vsftpd.virtual:

# sudo gedit /etc/pam.d/vsftpd.virtual


(5)追加下列:

#%PAM-1.0
auth       required     pam_userdb.so db=/etc/vsftpd/vsftpd-virtual-user
account    required     pam_userdb.so db=/etc/vsftpd/vsftpd-virtual-user
session    required     pam_loginuid.so


创建文件所在位置。

你需要为虚拟用户配置文件/目录的位置,键入以下命令:

# mkdir /home/vftp
# mkdir -p /home/vftp/{vivek,sayali}
# chown -R ftp:ftp /home/vftp


(6)重启FTP服务器

# service vsftpd restart


(7)测试

打开一个会话窗口,键入:

$ ftp localhost


(8)成功输出示例:

Connected to ftp.nixcraft.net.in.
Name (localhost:root): vivek
331 Please specify the password.[user now types in vivekpass]
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 


(9)问题处理

官方文档可能有帮助: ftp://vsftpd.beasts.org/users/cevans/untar/vsftpd-3.0.2/EXAMPLE/VIRTUAL_USERS 

默认创建的文件具有权限如 -rw(如果使用虚拟用户,则为ftp用户拥有)。要减少一些约束(像上面的,默认是077),就在你的vsftp.conf文件中设置 local_umask=022(-rw-r--r--权限),并重启服务。


  • http://j.mp/YunkHV - vsftpd - Secure, fast FTP server for UNIX-like systems security.appspot.com Secure, fast FTP server for UNIX systems

  • http://j.mp/Yunor2 - vsftpd - Wikipedia, the free encyclopedia: en.wikipedia.org vsftpd, which stands for "Very Secure FTPDaemon", is an FTP server for Unix-like systems, including Linux. It is licensed under the GNU General Public License. It supports IPv6 and SSL.

参考

  • http://j.mp/WsBpj0 - Configuring vsftpd for secure connections (TLS/SSL/SFTP) - VPSLink Wiki http://wiki.vpslink.com/Configuring_vsft... This article pertains specifically to vsftpd on CentOS. Except for the installation instructions it should be adaptable to other distributions as well..



0 0