Centos6.5 vsftpd 安装配置

Vsftp 安装配置

FTP图标
FTP图标

我使用的系统版本如下:

centos 6.5 64bit

[root@vCentos ~]# lsb_release -a
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.5 (Final)
Release: 6.5
Codename: Final
[root@vBlog ~]#


 

1.检查是否已经安装了vsftp

运行命令

rpm -qa|grep vsftpd

如果已经安装返回结果如下:

[root@vCentos ~]# rpm -qa|grep vsftpd
vsftpd-2.2.2-11.el6_4.1.x86_64
[root@vCentos ~]#

 

利用yum来安装vsftp

[root@vCentos ~]# yum -y install vsftpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base | 3.7 kB 00:00 
extras | 3.4 kB 00:00 
updates | 3.4 kB 00:00 
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:2.2.2-11.el6_4.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================
 Package Arch Version Repository Size
=======================================================================================================================================================================
Installing:
 vsftpd x86_64 2.2.2-11.el6_4.1 base 151 k

Transaction Summary
=======================================================================================================================================================================
Install 1 Package(s)

Total download size: 151 k
Installed size: 331 k
Downloading Packages:
vsftpd-2.2.2-11.el6_4.1.x86_64.rpm | 151 kB 00:00 
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
 Installing : vsftpd-2.2.2-11.el6_4.1.x86_64 1/1 
 Verifying : vsftpd-2.2.2-11.el6_4.1.x86_64 1/1 

Installed:
 vsftpd.x86_64 0:2.2.2-11.el6_4.1 

Complete!
[root@vCentos ~]# yum -y install lsb

 

2.关闭iptables 以及SELinux

service iptables stop
setenforce 0

 3. 修改vsftp的配置文件

[root@vCentos ~]# vi /etc/vsftpd/vsftpd.conf

取消下面内容前面的注释或添加

anonymous_enable=YES/NO  是否允许匿名用户访问 

chroot_list_enable=YES   限定用户不可以离开主目录

chroot_list_file=/etc/vsftpd/chroot_list 

loca_enable=YES/NO 本地用户是否可以访问 注:如果为NO 则所有虚拟用户都将不能访问原因:虚拟用户访问在主机上其实是以本地用户访问的

pam_service_name=vsftpd  pam认证文件名 在/etc/pam.d/vsftpd

guest_enable=YES    启用虚拟用户功能

guest_username=ftp  指定虚拟用户的宿主用户 –centos 里面已经有内置的ftp用户了(注:此用户在chroot_list_file=/etc/vsftpd/chroot_list文件里所指定的用户)

user_config_dir=/etc/vsftpd/vuser_conf 设置虚拟用户个人vsftp的服务配置文件

(此文件后面不能出现空格)

4. 创建 chroot_list_file=/etc/vsftpd/chroot_list文件

[root@localhost ~]#vi /etc/vsftpd/chroot_list

chroot_list 内容为:ftp

[root@vCentos ~]# cat /etc/vsftpd/chroot_list 
ftp
[root@vCentos ~]#

5. 创建虚拟用户目录(密码文本)

[root@vCentos ~]# vi /etc/vsftpd/vftpuser.list

一行用户名一行密码

[root@vCentos ~]# cat /etc/vsftpd/vftpuser.list 
80
8080
2373
23732373
8081
80818081

6.生成虚拟用户的DB文件

[root@vCentos ~]# db_load -T -t hash -f /etc/vsftpd/vftpuser.list /etc/vsftpd/vftpuser.db

7.生成虚拟用户的认证文件

[root@localhostvsftpd]# vi /etc/pam.d/vsftpd

#%PAM-1.0

session    optional    pam_keyinit.so    force revoke

auth       required     pam_listfile.so item=user sense=denyfile=/etc/vsftpd/ftpusers onerr=succeed

auth       required     pam_shells.so

auth       include      system-auth

account    include     system-auth

session    include     system-auth

session    required    pam_loginuid.so

注释掉/etc/pam.d/vsftpd中所有的内容 反正已经不要本地用户的认证了
增加以下两句:

auth      required     pam_userdb.so db=/etc/vsftpd/vftpuser
account   required     pam_userdb.so db=/etc/vsftpd/vftpuser

注:db=/etc/vsftpd/vftpuser 中的vftpuser 是你生成的虚拟用户的db文件

8.创建每个虚拟用户自己的配置文件

配置文件的路径是/etc/vsftpd/vsftpd.conf中的

user_config_dir=/etc/vsftpd/vuser_conf路径

在 /etc/vsftpd/vuser_conf/下面创建以用户名为名称的文件(名称是/etc/vsftpd/vftpuser.txtx 下面的奇数行)

[root@vCentos ~]# cat /etc/vsftpd/vftpuser.list 
80
8080
2373
23732373
8081
80818081
[root@localhostvsftpd]# mkdir vuser_conf
[root@localhostvsftpd]# vi /etc/vsftpd/vuser_conf/80

内容如下

local_root=/var/www/80(虚拟用户的根目录根据实际修改)
write_enable=YES (可写)
download_enable=YES
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
local_umask=022

9.给文夹权限

[root@localhostvsftpd]# chmod 777 /var/www/80

10.重启vsftpd

[root@localhostvsftpd]# service vsftpd restart

到此vsftp 配置完成

Leave a Comment