原文:https://www.iyunv.com/thread-44706-1-1.html
VSFTPD是一款小巧易用FTP服务器程序,vsftpd 在安全性、高性能及稳定性三个方面有上佳的表现。它提供的主要功能包括虚拟IP设置、虚拟用户、Standalone、inetd操作模式、强大的单用户设置能力及带宽限流等。在安全方面,它从原理上修补了大多数Wu-FTP、ProFTP,乃至BSD-FTP的安装缺陷,使用安全编码技术解决了缓冲溢出问题,并能有效避免“globbing”类型的拒绝服务攻击。目前正在使用vsftpd的官方网站有Red Hat、SuSE、Debian、GNU、GNOME、KDE、Gimp和OpenBSD等。它支持很多其他的 FTP 服务器不支持的特征。
比如:非常高的安全性需求
带宽限制
良好的可伸缩性
创建虚拟用户的可能性
IPv6支持
中等偏上的性能
分配虚拟 IP 的可能性
高速
(一)ftp原理与vsftp安装
ftp原理与vsftp安装
1.ftp原理
FTP Transfer Protocol 件传输协议的缩写,在RFC 959中具体说明。
FTP 会话时包含了两个通道,一个叫控制通道,一个叫数据通道。
控制通道:控制通道是和FTP服务器进行沟通的通道,连接FTP,发送FTP指令都是通过控制通道来完成的, PI称为控制连接
数据通道:数据通道是和FTP服务器进行文件传输或者列表的通道。
FTP 协议中,控制连接均有客户端发起,而数据连接有两种工作方式:PORT方式和PASV方式,DTP称为数据连接
PORT 模式(主动方式)
FTP 客户端首先和FTP Server的TCP 21端口建立连接,通过这个通道发送命令,客户端需要接收数据的时候在这个通道上发送PORT命令。 PORT命令包含了客户端用什么端口(一个大于1024的端口)接收数据。在传送数据的时候,服务器端通过自己的TCP 20端口发送数据。 FTP server必须和客户端建立一个新的连接用来传送数据。
PASV 模式(被动方式)
在建立控制通道的时候和PORT模式类似,当客户端通过这个通道发送 PASV 命令的时候,FTP server打开一个位于1024和5000之间的随机端口并且通知客户端在这个端口上传送数据的请求,然后FTP server 将通过这个端口进行数据的传送,这个时候FTP server不再需要建立一个新的和客户端之间的连接传送数据。
如果从C/S模型这个角度来说,PORT对于服务器来说是OUTBOUND,而PASV模式对于服务器是INBOUND,这一点请特别注意,尤其是在使用防火墙的企业里,这一点非常关键,如果设置错了,那么客户将无法连接。
2.安装vsftpd [iyunv@localhost /]# rpm -qa |grep vsftpd 查询是否安装了vsftpd(提示无)
[iyunv@localhost /]# mkdir /mnt/cdrom 创建挂载光驱目录文件
[iyunv@localhost /]# mount /dev/cdrom /mnt/cdrom/ 挂载光驱到刚创建目录
mount: block device /dev/cdrom is write-protected, mounting read-only
[iyunv@localhost /]# cd /mnt/cdrom/Server/
[iyunv@localhost Server]# rpm -ivh vsftpd-2.0.5-12.el5.i386.rpm 安装vsftp RPM包
warning: vsftpd-2.0.5-12.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:vsftpd ########################################### [100%]
[iyunv@localhost Server]# rpm -qa |grep vsftpd再查询是否安装了vsftpd
vsftpd-2.0.5-12.el5
[iyunv@localhost ~]# rpm -qi vsftpd 查询vsftpd详细信息
Name : vsftpd Relocations: (not relocatable)
Version : 2.0.5 Vendor: Red Hat, Inc.
Release : 12.el5 Build Date: 2007年12月13日 星期四 19时35分37秒
Install Date: 2009年12月26日 星期六 00时35分03秒 Build Host: ls20-bc1-14.build.redhat.com
Group : System Environment/Daemons Source RPM: vsftpd-2.0.5-12.el5.src.rpm
Size : 289673 License: GPL
Signature : DSA/SHA1, 2007年12月17日 星期一 23时43分34秒, Key ID 5326810137017186
Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
URL : http://vsftpd.beasts.org/
Summary : vsftpd - 非常安全 Ftp 守护进程
Description :
vsftpd 是一个非常安全 FTP 守护进程。它是完全从零开始编写的。
[iyunv@localhost ~]# rpm -ql vsftpd 列出vsftpd中包含文件
/etc/logrotate.d/vsftpd.log vsftpd的日志文件
/etc/pam.d/vsftpd PAM认证文件
/etc/rc.d/init.d/vsftpd 启动脚本
/etc/vsftpd vsftpd的配置文件存放的目录
/etc/vsftpd/ftpusers 禁止使用vsftpd的用户列表文件
/etc/vsftpd/user_list 禁止或允许使用vsftpd的用户列表文件
/etc/vsftpd/vsftpd.conf 主配置文件
/etc/vsftpd/vsftpd_conf_migrate.sh vsftpd操作的一些变量和设置
/usr/sbin/vsftpd vsftpd的主程序
其他一些说明文档和手册文件略!
/var/ftp 匿名用户主目录
/var/ftp/pub 匿名用户的下载目录
[iyunv@localhost /]# service vsftpd start 启动vsftpd
为 vsftpd 启动 vsftpd: [确定
[iyunv@localhost ~]# chkconfig --level 3 vsftpd on打开3级别随系统自动启动vsftpd
----------------------------------------------------------------------------------------------------
为 vsftpd 启动 vsftpd:
1.vsftpd的匿名用户默认只支持下载权限[iyunv@localhost /]# ftp 127.0.0.1 测试ftp用匿名用户登陆到本地服务器
Connected to 127.0.0.1.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (127.0.0.1:root): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 登陆成功(默认vsftp是开启匿名登录)
接下来测试匿名用户上传与下载
[iyunv@localhost ~]# touch /var/ftp/pub/test.txt 先在匿名用户下载目录创建一个test.txt文件
[iyunv@localhost /]# cd root
[iyunv@localhost ~]# touch test1.txt 进入根目录创建一个test1.txt文件,作为上传测试
ftp> cd pub
ftp> ls
227 Entering Passive Mode (127,0,0,12,92,5)
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 6 Dec 28 14:59 test.txt
226 Directory send OK.
ftp> mget test.txt 下载text.txt
mget test.txt?
227 Entering Passive Mode (127,0,0,12,123,33)
150 Opening BINARY mode data connection for test.txt (6 bytes).
226 File send OK.
6 bytes received in 0.0047 seconds (1.2 Kbytes/s)
ftp> !ls 测试是否下载到本地
anaconda-ks.cfg install.log install.log.syslog test1.txt test.txt 下载成功
ftp> put test1.txt 上传test1.txt
local: test1.txt remote: test1.txt
200 PORT command successful. Consider using PASV.
550 Permission denied. 请求被拒绝,说明没有上传权限
ftp> delete test.txt
550 Permission denied. 请求被拒绝,说明没有删除权限
2.让匿名用户支持上传功能,下载,创建目录文件的权限
要实现这个功能,必须做三件事情(测试环境是在关闭selinux情况下)
(1)修改/etc/vsftpd/vsftpd.conf---à去掉注释anon_upload_enable=YES(2)修改/etc/vsftpd/vsftpd.conf---à去掉注释anon_mkdir_write_enable=YES以上两个步骤如下:
[iyunv@localhost ~]# vi /etc/vsftpd/vsftpd.conf
25 # has an effect if the above global write enable is activated. Also, you will
26 # obviously need to create a directory writable by the FTP user.
27 anon_upload_enable=YES
28 #
29 # Uncomment this if you want the anonymous FTP user to be able to create
30 # new directories.
31 anon_mkdir_write_enable=YES
32 #
33 # Activate directory messages - messages given to remote users when they
34 # go into a certain directory.
35 dirmessage_enable=YES
(3)文件系统中FTP匿名用户对某个目录有写权限
默认FTP根目录/var/ftp是不允许更改权限的,我们对其它目录权限进行更改做为匿名的工作目录。
chmod -R 777 /var/pub
[iyunv@localhost ftp]# service vsftpd restart 重启vsftpd服务
关闭vsftpd: [确定]
为vsftpd启动vsftpd: [确定]
提示:要想让匿名用户支持删除和更名权限,必须在vsftpd.conf加入以下参数
anon_other_write_enable=YES 允许匿名账号具有删除.更名权限