一.总的分为这几个步骤
1.       安装 VSFTPD 软件及 DB 软件

2.       创建一个虚拟账户,把他当作虚拟用户的宿主。

3.       配置 vsftp.conf 配置文件,添加新虚拟用户相关内容

4.       创建一个虚拟用户数据文件

5.       使用 DB4 把用户数据文件 HASH 一下,这样用户数据文件才能生效

6.       修改 PAM 里的 VSFTPD 用户认证文件,注释掉其他,添加与用户数据的关联信息

7.       创建一个虚拟用户目录,里面放着虚拟用户配置文件

8.       可以 CP 并修改原先 vsftpd.conf 配置文件给虚拟用户目录,当作虚拟用户的配置文件。

9.       创建一个虚拟用户的根目录,根目录就是存放上传下载数据的内容。

二.实际操作

1.       安装这两个服务安装包

Yum install vsftpd.i686 –y

Yum install db4-utils-4.7.25-16.el6.i686 –y

接下来我们开始详细的配置过程拉

 

2.       首先我们来创建一个虚拟账户,后面我们的虚拟用户都是寄托在他身上的,因为虚拟用户在系统里是不存在的,所以要寄托一个系统里的用户,这样关联了才能登入的。

useradd virtuser -s /sbin/nologin

为了安全,我们把 virtuser 账户设置为不可登入的,因为系统的用户我们是不允许登入的。

3.       接下来我们开始配置一下 vsftp.conf 文件,我们详解配置文件的内容,并在里面添加虚拟账户的相关信息。

Cp /etc/vsftpd/vsftpd.conf  /etc/vsftpd/vsftpd.conf.bak

备份一下配置文件

Vi /etc/vsftpd/vsftpd.conf

# Example config file /etc/vsftpd/vsftpd.conf

#

# The default compiled in settings are fairly paranoid. This sample file

# loosens things up a bit, to make the ftp daemon more usable.

# Please see vsftpd.conf.5 for all compiled in defaults.

#

# READ THIS: This example file is NOT an exhaustive list of vsftpd options.

# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's

# capabilities.

#

# Allow anonymous FTP? (Beware - allowed by default if you comment this out).

anonymous_enable=NO

不允许匿名用户登入

#

# Uncomment this to allow local users to log in.

local_enable=YES

本地用户允许登入

#

# Uncomment this to enable any form of FTP write command.

write_enable=YES

允许写入

#

# Default umask for local users is 077. You may wish to change this to 022,

# if your users expect that (022 is used by most other ftpd's)

local_umask=022

上传后的文件权限反码

#

# Uncomment this to allow the anonymous FTP user to upload files. This only

# has an effect if the above global write enable is activated. Also, you will

# obviously need to create a directory writable by the FTP user.

anon_upload_enable=NO

禁止匿名账户上传

#

# Uncomment this if you want the anonymous FTP user to be able to create

# new directories.

anon_mkdir_write_enable=NO

禁止匿名账户创建目录

#

# Activate directory messages - messages given to remote users when they

# go into a certain directory.

dirmessage_enable=YES

开启目录标语功能

#

# Activate logging of uploads/downloads.

xferlog_enable=YES

开启日志功能

#

# Make sure PORT transfer connections originate from port 20 (ftp-data).

connect_from_port_20=YES

使用端口 20 连接

#

# If you want, you can arrange for uploaded anonymous files to be owned by

# a different user. Note! Using "root" for uploaded files is not

# recommended!

chown_uploads=NO

禁止上传的文件更改宿主

#chown_username=whoever

#

# You may override where the log file goes if you like. The default is shown

# below.

xferlog_file=/var/log/vsftpd.log

日志记录文件的存放目录。

#

# If you want, you can have your log file in standard ftpd xferlog format.

# Note that the default log file location is /var/log/xferlog in this case.

xferlog_std_format=YES

日志文件使用标准格式来记录日志内容

#

# You may change the default value for timing out an idle session.

idle_session_timeout=600

空闲会话超时时间设定,单位秒

#

# You may change the default value for timing out a data connection.

data_connection_timeout=120

数据连接超时时间设置,单位秒

#

# It is recommended that you define on your system a unique user which the

# ftp server can use as a totally isolated and unprivileged user.

#nopriv_user=vsfptd

VSFTPD 服务是由哪个用户来运行的,我们在这里可以不管他的。

# Enable this and the server will recognise asynchronous ABOR requests. Not

# recommended for security (the code is non-trivial). Not enabling it,

# however, may confuse older FTP clients.

async_abor_enable=YES

数据的异步传输功能开启

#

# By default the server will pretend to allow ASCII mode but in fact ignore

# the request. Turn on the below options to have the server actually do ASCII

# mangling on files when in ASCII mode.

# Beware that on some FTP servers, ASCII support allows a denial of service

# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd

# predicted this attack and has always been safe, reporting the size of the

# raw file.

# ASCII mangling is a horrible feature of the protocol.

ascii_upload_enable=YES

使用 ASCII 模式上传

ascii_download_enable=YES

使用 ASCII 模式下载

#

# You may fully customise the login banner string:

ftpd_banner=Welcome to blah FTP service.

FTP 登入后显示的标语

#

# You may specify a file of disallowed anonymous e-mail addresses. Apparently

# useful for combatting certain DoS attacks.

#deny_email_enable=YES

# (default follows)

#banned_email_file=/etc/vsftpd/banned_emails

#

# You may specify an explicit list of local users to chroot() to their home

# directory. If chroot_local_user is YES, then this list becomes a list of

# users to NOT chroot().

chroot_local_user=YES

禁止用户登出自己的根目录

#chroot_list_enable=YES

# (default follows)

#chroot_list_file=/etc/vsftpd/chroot_list

#

# You may activate the "-R" option to the builtin ls. This is disabled by

# default to avoid remote users being able to cause excessive I/O on large

# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume

# the presence of the "-R" option, so there is a strong case for enabling it.

ls_recurse_enable=NO

关闭 ls –R 功能,因为使用此命令会有给服务器增加负载的危险。

#

# When "listen" directive is enabled, vsftpd runs in standalone mode and

# listens on IPv4 sockets. This directive cannot be used in conjunction

# with the listen_ipv6 directive.

listen=YES

开启监听,使该 VSFTP 拥有自己的守护进程。

#

# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6

# sockets, you must run two copies of vsftpd with two configuration files.

# Make sure, that one of the listen options is commented !!

#listen_ipv6=YES

 

pam_service_name=vsftpd

设置 vsftp 使用 /etc/pam.d/vsftpd 这个 PAM 认证文件。

userlist_enable=YES

用户列表开启,在 /etc/vsftpd/user_list 里的用户将不得使用 FTP

tcp_wrappers=YES

控制功能开启,他就是对应 /etc/host.allow /etc/host.deny 文件。

 

#### 下面就是新添加的内容 ####

guest_enable=YES     

开启虚拟用户功能

guest_username=virtuser      

设置虚拟用户的宿主,就是虚拟账户

user_config_dir=/etc/vsftpd/vconf 

设置虚拟用户的配置文件目录,每一个虚拟用户都需要有自己私有的配置文件

virtual_use_local_privs=YES

设置虚拟用户的权限符合虚拟账户的对应的权限,而虚拟账户的权限就是 /etc/vsftpd.vsftpd.conf 里设置的,如果虚拟账户在 vsftpd.conf 中关闭了某些功能,则虚拟用户将无法使用该功能,而虚拟账户开启了某些功能,则虚拟用户可以自己设置如关闭或开启使用。

好了,现在配置文件已经配置好了。开始创建虚拟用户数据文件

3 . 我们现在开始创建一个用户数据文件拉,

touch /etc/vsftpd/virtuser.txt

   vi /etc/vsftpd/virtuser.txt

   user01    ---- 虚拟用户 1

   123456    ---- 虚拟用户 1 密码

User02    ---- 虚拟用户 2

123456    ---- 虚拟用户 2 密码

保存退出

接着使用 DB hash 一下这个用户数据文件,使得 VSFTPD 服务能使用它

Db_load –T –t hash –f /etc/vsftpd/virtuser.txt   /etc/vsftpd/virtuser.db

记住,用户数据文件是一行用户一行密码的。

Db_load –T –t hash –f 一定要使用,不然无法使用用户数据文件的用户密码等都无法使用了。

4.       现在我们开始修改 PAM 文件。

Vi /etc/pam.d/vsftpd

#%PAM-1.0

session    optional     pam_keyinit.so    force revoke

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

auth       required     pam_shells.so

auth       include      password-auth

account    include      password-auth

session    required     pam_loginuid.so

session    include      password-auth

这些是默认的内容噢。。我们现在要把他们全部的注释掉然后再添加两行内容了

#%PAM-1.0

#session    optional     pam_keyinit.so    force revoke

#auth       required    pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed

#auth       required    pam_shells.so

#auth       include     password-auth

#account    include     password-auth

#session    required     pam_loginuid.so

#session    include     password-auth

auth   required  /lib/security/pam_userdb.so  db=/etc/vsftpd/virtuser

account required /lib/security/pam_userdb.so  db=/etc/vsftpd/virtuser

以上两行就是我们添加的内容了,

注意: /etc/vsftpd/virtuser 是经过 hash 的用户数据文件,不用在后面再添加上 .db 了。

7. 我们现在开始创建一个虚拟用户目录,里面放着的是虚拟用户的配置文件,就是和 VSFTP.CONF 差不多,但是内容不多,主要还是根据 /etc/vsftpd/vsftpd.conf , 记住,用户的配置文件名一定好喝你虚拟用户登入名是一样的。

   Mkdir /etc/vsftpd/vconf

   Vi /etc/vsftpd/vconf/user01

   local_root=/opt/vsftp/user01  --- 指定 user01 的根目录

download_enable=YES      ----- 允许 user01 下载文件  

anon_upload_enable=YES    ----- 允许 user01 上传文件

anon_mkdir_write_enable=YES   ------ 允许 user01 创建和删除目录

anon_max_rate=500000   -------- 最大传输绿为 50000 bit/s

 

user02 操作也是一样的,直接拷贝 user01 的配置,然后更改下根目录就可以了

8 .现在我们可以创建虚拟用户的根目录拉。。

   Mkdir /opt/vsftp/user01  /opt/vsftp/user02

   然后在目录里创建一些文件,用于测试用

   Mkdir /opt/vsftp/user01/ll

   创建完后我们开始对每一个用户的权限重新分配

   Chown virtuser:virtuser –R /opt/vsftp/

 

然后 service vsftpd restart  重启 VSFTP 服务

三.实际测试。

  我们现在开始测试:

[root@CentOS vsftpd]# ftp

ftp> open 192.168.0.1

Connected to 192.168.0.1 (192.168.0.1).

220 Welcome to blah FTP service.

Name (192.168.0.1:root): user02

331 Please specify the password.

Password:

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> dir

227 Entering Passive Mode (192,168,0,1,83,74).

150 Here comes the directory listing.

drwxr-xr-x    2 503      503          4096 Jan 04 04:29 11

226 Directory send OK.

ftp>

 

 

 

 

 

Windows 上测试



可以上传和下载拉。。
有问题希望能指出。。谢谢了。。。