Vsftp服务安装搭建,虚拟用户配置

vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序。特点是小巧轻快,安全易用。
vsftpd 的名字代表"very secure FTP daemon", 安全是它的开发者 Chris Evans 考虑的首要问题之一。在这个 FTP 服务器设计开发的最开始的时候,高安全性就是一个目标。 目前在开源操作系统中常用的FTPD套件主要还有ProFTPD、PureFTPd和wuftpd等。更多请百度谷歌一下
安装环境:

centos 2.6.28 #1 SMP Sat Dec 17 01:54:27 CST 2011 x86_64 x86_64 x86_64 GNU/Linux
vsftpd.x86_64,版本2.0.5-24.el5_8.1

首先安装vsftpd、pam验证模块、db4数据存储(pam-devel,pam-devel,pam、db4-utils),直接把相关的都装上,省着麻烦

yum  install   vsftpd  pam pam-* db4 db4-*

安装好后,进入vsftpd的配置文件目录

cd /etc/vsftpd/

创建一个保存用户及密码的文件

touch virtual_login
vim  virtual_login 

向其添加用户(一行用户一行是密码),并保存

kinggoouser
kinggoopasswd
comuser
compasswd

将文本内的帐号及密码添加到db4的数据库文件内

db_load -T  -t hash -f /etc/vsftpd/virtual_login /etc/vsftpd/virtual_login.db

配置pam内vsftpd的验证文件,添加验证模块路径,编辑vsftpd的pam配置文件

vim  /etc/pam.d/vsftpd

将其原内容全部注释掉,然后想其内添加

auth    required        /lib64/security/pam_userdb.so   db=/etc/vsftpd/virtual_login
account required        /lib64/security/pam_userdb.so   db=/etc/vsftpd/virtual_login

添加或如下所示

cat  /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     system-auth
#account    include     system-auth
#session    include     system-auth
#session    required     pam_loginuid.so
auth    required        /lib64/security/pam_userdb.so   db=/etc/vsftpd/virtual_login
account required        /lib64/security/pam_userdb.so   db=/etc/vsftpd/virtual_login

创建一个vsftpd服务的用户vsftpd,你也可以使用-d来指定他的家目录

useradd -s /sbin/nologin vsftpd
useradd -d /var/ftp/kinggoouser -s /sbin/nologin ftp.kinggoouser
useradd -d /var/ftp/comuser -s /sbin/nologin ftp.comuser

OK,看一下我的vsftpd的配置文件

cat  /etc/vsftpd/vsftpd.conf |grep -v  -E "^(#|$)"
#--------内容如下------------
anonymous_enable=NO			#不允许匿名访问
local_enable=YES			#设定本地用户可以访问。注意:主要是为虚拟宿主用户,如果该项目设定为NO那么所有虚拟用户将无法访问
write_enable=YES			#允许写操作
local_umask=022				#创建或上传后文件的权限掩码
anon_upload_enable=NO		#禁止匿名用户上传
anon_mkdir_write_enable=NO	#禁止匿名用户创建目录
dirmessage_enable=YES		#进入目录时可以显示一些设定的信息,可以通过message_file=.message来设置
xferlog_enable=YES			#开启日志
connect_from_port_20=YES	#主动连接的端口号
chown_uploads=NO			#设定禁止上传文件更改宿主
xferlog_file=/var/log/vsftpd.log	#日志路径,记得自己创建一下并且对这个文件进行chown  vsftpd.vsftpd /var/log/vsftpd.log
xferlog_std_format=YES		#就是格式话日志格式的,你懂得。使用wu ftp软件时设置yes就行
nopriv_user=vsftpd			#因为我们把vsftpd的shell设置为nobody 了,所以 这个地方写vsftpd就可以啦!当然或者可以写成系统内的nobody 
async_abor_enable=YES		#设定支持异步传输功能
ascii_upload_enable=YES		#设定支持ASCII模式的上传
ascii_download_enable=YES	#设定支持ASCII模式的上传
ftpd_banner=Welcome to kinggoo.com FTP service.	#登陆欢迎语
chroot_list_enable=YES			#限定在自己的目录内,不让他出去,就比如如果设置成NO,那么当你登陆到ftp的时候,可以访问服务器的其他一些有权限目录。设置为YES后即,锁定你的目录了
chroot_list_file=/etc/vsftpd/chroot_list	#待会要把用户写到这个里面,写到这里的用户乖乖的呆在家目录下吧
listen=YES	#以standalone方式来启动
pam_service_name=vsftpd		#/etc/pam.d/下的vsftpd文件
userlist_enable=YES		#在/etc/vsftpd/user_list中的用户将不得使用FTP 
tcp_wrappers=YES	#支援 TCP Wrappers 的防火墙机制
guest_enable=YES	#启用虚拟用户功能
virtual_use_local_privs=YES	#虚拟用户的权限符合他们的宿主用户
user_config_dir=/etc/vsftpd/vsftpd_config	#虚拟用户个人vsftpd的配置文件存放路径。vsftpd_config是文件夹啊。注意:配置文件名必须和虚拟用户名相同

好了,保存一下上面的配置

创建一下保存虚拟用户配置文件的地方

mkdir /etc/vsftpd/vsftpd_config/

顺便把那个日志文件也创建了吧,怕忘记

touch /var/log/vsftpd.log 
chown -R vsftpd.vsftpd /var/log/vsftpd.log 

创建要将哪些用户固定在家目录的配置文件

touch /etc/vsftpd/chroot_list
#例chroot_list内容:
kinggoouser
kinggoouser2

将需要固定用户目录的虚拟用户名字写进去即可。每行写一个即可
好了,进入保存虚拟用户配置的地方

cd /etc/vsftpd/vsftpd_config/

创建kinggoouser,还有comuser配置文件(如果你有其他用户,则一一效仿即可,每个配置项最后都不能有空格)

cat kinggoouser
#---------内容如下--------------
guest_enable=yes	#起用虚拟用户   ,centos下yes必须为小写字母
guest_username=ftp.kinggoouser	#映射本地虚拟用户
local_root=/var/ftp/kinggoouser		#如果当时创建用户的时候锁定一个目录了,那就可以不写
idle_session_timeout=600	#用户会话空闲后10分钟,嘿嘿你懂的
data_connection_timeout=120		#将数据连接空闲2分钟断,如上↑
max_clients=10	#最大客户端连接数
max_per_ip=5	#每个ip最大连接数
local_max_rate=0	#限制上传速率,0为无限制

保存退出

cat comuser
guest_enable=yes	#起用虚拟用户   ,centos下yes必须为小写字母
guest_username=ftp.comuser	#映射本地虚拟用户
local_root=/var/ftp/comuser		#如果当时创建用户的时候锁定一个目录了,那就可以不写
idle_session_timeout=600	#用户会话空闲后10分钟,嘿嘿你懂的
data_connection_timeout=120		#将数据连接空闲2分钟断,如上↑
max_clients=10	#最大客户端连接数
max_per_ip=5	#每个ip最大连接数
local_max_rate=30000000	#限制上传速率,0为无限制

保存退出
不过其实你还可以向上面的文件内添加这么一行

#这里是你给他设的权限 ,可以参考本文下面的内容。命令解释部分
cmds_allowed=ABOR,CWD,LIST,MDTM,NLST,PASS,PASV,PORT,PWD,QUIT,RETR,SIZE,TYPE,USER,ACCT,APPE
#

#########
重启服务
试试使用虚拟用户登陆

Vsftp服务安装搭建,虚拟用户配置 for  kinggoo.com


OK,没问题登陆成功

因为我们设置userlist_enable=YES,如果你向 /etc/vsftpd/user_list中添加虚拟用户名,那就无法登陆了

cat /etc/vsftpd/user_list 
#------内容如下
# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
# for users that are denied.
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
kinggoouser    # < <<<<<<<<<<<<<在这里哦~~~~~~

Vsftp服务安装搭建,虚拟用户配置 for  kinggoo.com
登陆失败了吧,直接530了

The end.

好了到此为此,下面有很多我参考的一些资料,敬请观摩!结束

参考内容:

db_load命令用法

[root@kinggoo.com RPMS]# rpm -ivh db4-utils-4.2.52-7.1.i386.rpm
warning: db4-utils-4.2.52-7.1.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
Preparing…                ########################################### [100%]
   1:db4-utils              ########################################### [100%]
[root@kinggoo.com RPMS]# db_
db_archive     db_deadlock    db_dump185     db_printlog    db_stat        db_verify
db_checkpoint  db_dump        db_load        db_recover     db_upgrade
[root@kinggoo.com RPMS]# db_load
usage: db_load [-nTV] [-c name=value] [-f file]
        [-h home] [-P password] [-t btree | hash | recno | queue] db_file
      

db_load命令需要安装 db4-utils这个软件包,在RHEL4.5中,这个软件包在第三个VCD光盘中.
db_load命令几个相关选项:

-T
The -T option allows non-Berkeley DB applications to easily load text files into databases.
If the database to be created is of type Btree or Hash, or the keyword keys is specified as set, the input must be paired
lines of text, where the first line of the pair is the key item, and the second line of the pair is its corresponding data
item. If the database to be created is of type Queue or Recno and the keywork keys is not set, the input must be lines of text, where each line is a new data item for the database.
选项-T允许应用程序能够将文本文件转译载入进数据库。由于我们之后是将虚拟用户的信息以文件方式存储在文件里的,为了让Vsftpd这个应用程序能够通过文本来载入用户数据,必须要使用这个选项。
If the -T option is specified, the underlying access method type must be specified using the -t option.
如果指定了选项-T,那么一定要追跟子选项-t

-t
Specify the underlying access method. If no -t option is specified, the database will be loaded into a database of the same type as was dumped; for example, a Hash database will be created if a Hash database was dumped.
Btree and Hash databases may be converted from one to the other. Queue and Recno databases may be converted from one to the other. If the -k option was specified on the call to db_dump then Queue and Recno databases may be converted to Btree or Hash, with the key being the integer record number.
子选项-t,追加在在-T选项后,用来指定转译载入的数据库类型。扩展介绍下,-t可以指定的数据类型有Btree、Hash、Queue和Recon数据库。

-f
参数后面接包含用户名和密码的文本文件,文件的内容是:奇数行用户名、偶数行密码,例如:
kinggoouser
kinggoopasswd
comuser
compasswd

将用户信息文件转换为数据库并使用hash加密

db_load -T -t hash -f /etc/vsftpd/logins.txt /etc/vsftd/vsftpd_login.db


cmds_allowed内添加的命令解释:

CWD - change working directory 更改目录
DELE - delete a remote file 删除文件
LIST - list remote files 文件列表
MKD - make a remote directory 新建文件夹
NLST - name list of remote directory 目录列表
PWD - print working directory 显示当前工作目录
RETR - retrieve a remote file 下载文件
RMD - remove a remote directory 删除目录
RNFR - rename from 重命名
RNTO - rename to 重命名
STOR - store a file on the remote host 上传文件
ABOR - abort a file transfer 取消文件传输
MDTM - return the modification time of a file 返回文件的更新时间
PASS - send password 发送口令
PASV - enter passive mode 被动传输模式
PORT - open a data port 打开一个传输端口
QUIT - terminate the connection 退出
SITE - site-specific commands 站点特定的命令
SIZE - return the size of a file 返回文件大小
TYPE - set transfer type 设置传输类型
USER - send username 发送用户名
ACCT - send account information 发送帐户信息
APPE - append to a remote file 追加传输
CDUP - CWD to the parent of the current directory 更改目录到当前目录的父目录
HELP - return help on using the server 帮助信息
MODE - set transfer mode 设置传输模式
NOOP - do nothing 无操作
REIN - reinitialize the connection 重新初始化连接
STAT - return server status 返回服务器状态
STOU - store a file uniquely 
STRU - set file transfer structure 设置文件传输结构
SYST - return system type 返回系统类型

解决某些问题时:

在无法创建文件夹的时候 主要是553这种错误。这是SELinux的设置命令.这个一般你关掉了selinux就不需要搞了!

setsebool -P ftpd_disable_trans 1 
service vsftpd restart 

模式切换 主要是425 Use PORT or PASV first,时

quote PASV
quote  PORT
或
在linux的ftp服务器上执行下列命令即可解决
modprobe ip_nat_ftp
modprobe ip_conntrack_ftp

“FTP时显示500 Illegal PORT command的解决”,但这两种方法都没解决!因为我的是在windows上时才会出现,所以我对他进行了IE的设置,设置方法请参考下面的信息

常见的FTP客户端软件PORT方式与PASV方式的切换方法。 

    大部分FTP客户端默认使用PASV方式。IE默认使用PORT方式。
    在大部分FTP客户端的设置里,常见到的字眼都是“PASV”或“被动模式”,极少见到“PORT”或“主动模式”等字眼。因为FTP的登录方式只有两种:PORT和PASV,取消PASV方式,就意味着使用PORT方式。
IE:
    工具 -> Internet选项 -> 高级 -> “使用被动FTP”(需要IE6.0以上才支持)。是取消
CuteFTP:
    Edit -> Setting -> Connection -> Firewall -> “PASV Mode”
或File -> Site Manager,在左边选中站点 -> Edit -> “Use PASV mode”
FlashGet:
    工具 -> 选项 -> 代理服务器 -> 直接连接 -> 编辑 -> “PASV模式”
FlashFXP:
    选项 -> 参数选择 -> 代理/防火墙/标识 -> “使用被动模式”
或站点管理 -> 对应站点 -> 选项 -> “使用被动模式”
或快速连接 -> 切换 -> “使用被动模式”
LeechFTP:
    Option -> Firewall -> Do not Use

vsftpd.conf的参数:

Anonymous_enable=yes	允许匿名登陆
Dirmessage_enable=yes	切换目录时,显示目录下.message的内容
Local_umask=022	FTP上本地的文件权限,默认是077
Connect_form_port_20=yes	启用FTP数据端口的数据连接 *
Xferlog_enable=yes	激活上传和下传的日志
Xferlog_std_format=yes	使用标准的日志格式
Ftpd_banner=XXXXX	欢迎信息
Pam_service_name=vsftpd	验证方式 *
Listen=yes	独立的VSFTPD服务器 *
Anon_upload_enable=yes	开放上传权限
Anon_mkdir_write_enable=yes	可创建目录的同时可以在此目录中上传文件
Write_enable=yes	开放本地用户写的权限
Anon_other_write_enable=yes	匿名帐号可以有删除的权限
Anon_world_readable_only=no	放开匿名用户浏览权限
Ascii_upload_enable=yes	启用上传的ASCII传输方式
Ascii_download_enable=yes	启用下载的ASCII传输方式
Banner_file=/var/vsftpd_banner_file	用户连接后欢迎信息使用的是此文件中的相关信息
Idle_session_timeout=600(秒)	用户会话空闲后10分钟
Data_connection_timeout=120(秒)	将数据连接空闲2分钟断
Accept_timeout=60(秒)	将客户端空闲1分钟后断
Connect_timeout=60(秒)	中断1分钟后又重新连接
Local_max_rate=50000(bite)	本地用户传输率50K
Anon_max_rate=30000(bite)	匿名用户传输率30K
Pasv_min_port=50000	将客户端的数据连接端口改在
Pasv_max_port=60000	50000—60000之间
Max_clients=200	FTP的最大连接数
Max_per_ip=4	每IP的最大连接数
Listen_port=5555	从5555端口进行数据连接
Local_enble=yes	本地帐户能够登陆
Write_enable=no	本地帐户登陆后无权删除和修改文件
下面这是一组	
Chroot_local_user=yes	本地所有帐户都只能在自家目录
Chroot_list_enable=yes	文件中的名单可以调用
Chroot_list_file=/任意指定的路径/vsftpd.chroot_list	前提是chroot_local_user=no
这又是一组	
Userlist_enable=yes	在指定的文件中的用户不可以访问
Userlist_deny=yes	
Userlist_file=/指定的路径/vsftpd.user_list
又开始单的了	
Banner_fail=/路径/文件名	连接失败时显示文件中的内容
Ls_recurse_enable=no	
Async_abor_enable=yes	
one_process_model=yes	
Listen_address=10.2.2.2	将虚拟服务绑定到某端口
Guest_enable=yes	虚拟用户可以登陆
Guest_username=所设的用户名	将虚拟用户映射为本地用户
User_config_dir=/任意指定的路径/为用户策略自己所建的文件夹	指定不同虚拟用户配置文件的路径
又是一组	
Chown_uploads=yes	改变上传文件的所有者为root
Chown_username=root	
又是一组	
Deny_email_enable=yes	是否允许禁止匿名用户使用某些邮件地址
Banned_email_file=//任意指定的路径/xx/	
又是单的	
Pasv_enable=yes	服务器端用被动模式
User_config_dir=/任意指定的路径//任意文件目录	指定虚拟用户存放配置文件的路径

我也参考了不少的文章 ,主要让我这次有兴趣搞下虚拟用户ftp是因为<a href="htpp://dngood.blog.51cto.com" target="_blank" > dngood </a>,他给我发了篇vsftpd的文章,所以让我来了兴致。

参考这篇文章

http://www.linuxeden.com/html/netadmin/20070518/26857.html
http://www.linuxeden.com/html/netadmin/20070518/26857.html
http://linux.vbird.org/linux_server/0410vsftpd.php  鸟哥私房菜嘎嘎~我就是看这书开始linux的
http://www.2cto.com/os/201112/115708.html

当然少不了百度谷歌了,也有我的博客KingGoo博客贴金了,贴金了

- THE END -
版权声明:
转载原创文章请注明,文章出处://kinggoo.com
原文地址:https://kinggoo.com/app-installvsftpdconf.htm
发表评论?

22 条评论。

  1. 响应: 425 Security: Bad IP connecting.

    问题解决:
    1.#vim /etc/vsftpd/vsftpd.conf
    2.添加:pasv_promiscuous=YES
    3.保存后退出
    4.重启vsftpd #service vsftpd restart

  2. 当我们限定了用户不能跳出其主目录之后,使用该用户登录FTP时往往会遇到这个错误:
    [html] view plain copy
    500 OOPS: vsftpd: refusing to run with writable root inside chroot ()

    这个问题发生在最新的这是由于下面的更新造成的:
    [html] view plain copy
    – Add stronger checks for the configuration error of running with a writeable root directory inside a chroot(). This may bite people who carelessly turned on chroot_local_user but such is life.

    从2.3.5之后,vsftpd增强了安全检查,如果用户被限定在了其主目录下,则该用户的主目录不能再具有写权限了!如果检查发现还有写权限,就会报该错误。
    要修复这个错误,可以用命令chmod a-w /home/user去除用户主目录的写权限,注意把目录替换成你自己的。或者你可以在vsftpd的配置文件中增加下列两项中的一项:

    allow_writeable_chroot=YES

  3. NAT转发Ftp数据 | KingGoo技术博客 - pingback on 2015 年 12 月 28 日 在 15:55
  4. 按照文章配置完成了,可以使用虚拟用户登录。
    但是无法创建文件夹,无法上传,只能浏览和下载
    我根据网上的参考,将SELinux关闭,改为 SELINUX=disabled ,仍不能解决。

  5. 到了最后,我开始尝试连接登陆ftp
    提示输入用户、密码后
    出现
    500 OOPS: bad bool value in config file for: guest_enable
    Login failed.
    421 Service not available, remote server has closed connection

    网上搜索了下,说是vsftpd.conf文件不能含有空格。
    楼主遇到过这问题吗?

  6. 将需要固定用户目录的用户名字写入chroot_list,是指将虚拟用户名:kinggoouser写入,还是将真实用户名:ftp.kinggoouser写入?

  7. 创建该文件
    cat kinggoouser
    是否是cat > kinggoouser

  8. 执行到chown 600 vsftpd.vsftpd /var/log/vsftpd.log
    提示:chown: 无法访问 “vsftpd.vsftpd”: 没有那个文件或目录
    这是为何?

  9. FTP备份用的一个Shell方法函数 | KingGoo技术博客 - pingback on 2013 年 04 月 03 日 在 13:26

回复给 Tscccn ¬
取消回复


此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据