`
k_lb
  • 浏览: 802246 次
  • 性别: Icon_minigender_1
  • 来自: 郑州
社区版块
存档分类
最新评论
  • kitleer: 据我所知,国内有款ETL调度监控工具TaskCTL,支持ket ...
    kettle调度

CentOs vsftp

阅读更多
Centos 6 配置 vsftp 同时使用本地用户和虚拟用户
一、安装vsftp
1.安装Vsftpd服务相关部件
yum install vsftpd*
2.确认安装PAM服务相关部件
yum install pam*
3.安装DB4部件包
安装一个db4的包,用来支持文件数据库。
yum install db4*
二、配置vsftp
1.修改/etc/vsftpd/vsftpd.conf
vi /etc/vsftpd/vsftpd.conf
# 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=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# The target log file can be vsftpd_log_file or xferlog_file.
# This depends on setting xferlog_std_format parameter
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# 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=YES
#chown_username=whoever
#
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
xferlog_file=/var/log/vsftpd.log
#
# Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
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=ftpsecure
#
# 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_download_enable=YES
#
# You may fully customise the login banner string:
ftpd_banner=Welcome to blah FTP service.
#
# 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=YES
#
# 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
#
listen_port=21
# 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
userlist_enable=YES
userlist_deny=YES
tcp_wrappers=YES
#cmds_allowed=ABOR,CWD,LIST,MDTM,MKD,NLST,PASS,PASV,PORT,PWD,QUIT,RETR,RNT
O,SIZE,STC
#enable virtual user
guest_enable=YES
#指定虚拟用户的宿主用户
guest_username=ftp
#设定虚拟用户的权限符合他们的宿主用户
virtual_use_local_privs=YES
#设定虚拟用户个人Vsftp的配置文件存放路径,也就是说,这个被指定的目录里,将存放每个Vsftp虚拟用
户个性的配置文件,一个需要注意的地方就是这些配置文件名必须和虚拟用户名相同。
user_config_dir=/etc/vsftpd/vconf
2.建立Vsftpd的日志文件,并更该属主为Vsftpd的服务宿主用户
touch /var/log/vsftpd.log
chown ftp.ftp /var/log/vsftpd.log
3.建立虚拟账号存取文件路径
mkdir /etc/vsftpd/vconf/
三、制作虚拟用户数据库文件
1.建立了一个虚拟用户名单文件,这个文件就是来记录vsftpd虚拟用户的用户名和口令的数据文件
touch /etc/vsftpd/virtualusers
2.编辑虚拟用户名单文件:
vi /etc/vsftpd/virtualusers
test
test
编辑这个虚拟用户名单文件,在其中加入用户的用户名和口令信息。格式很简单:“一行用户名,一行口令”。
3.用db4工具生成虚拟用户数据文件:
db_load -T -t hash -f /etc/vsftpd/virtualusers /etc/vsftpd/virtualusers.db
以后每次添加新的用户都需要重新db_load -T -t hash -f 生成
四、设定PAM验证文件,并指定虚拟用户数据库文件进行读取
1.备份pam验证文件
cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd.bak
2.更改pam验证文件
vi /etc/pam.d/vsftpd
#%PAM-1.0
auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/virtualusers
account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/virtualusers
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是指对用户的用户名口令进行验证。
这里的accout是指对用户的帐户有哪些权限哪些限制进行验证。
其后的sufficient表示充分条件,也就是说,一旦在这里通过了验证,那么也就不用经过下面剩下的验证步
骤了。相反,如果没有通过的话,也不会被系统立即挡之门外,因为sufficient的失败不决定整个验证的失
败,意味着用户还必须将经历剩下来的验证审核。
再后面的/lib/security/pam_userdb.so表示该条审核将调用pam_userdb.so这个库函数进行。
最后的db=/etc/vsftpd/virtualusers则指定了验证库函数将到这个指定的数据库中调用数据进行验证。
五、虚拟用户的配置
1.规划好虚拟用户的主路径:
mkdir /opt/vsftp/
2.建立测试用户的FTP用户目录:
mkdir /opt/vsftp/test
3.建立虚拟用户配置文件模版:
cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vconf/vconf.tmp
4.定制虚拟用户模版配置文件:
vi /etc/vsftpd/vconf/vconf.tmp
--------------------------------
local_root=/opt/vsftp/virtualuser
指定虚拟用户的具体主路径。
anonymous_enable=NO
设定不允许匿名用户访问。
write_enable=YES
设定允许写操作。
local_umask=022
设定上传文件权限掩码。
anon_upload_enable=NO
设定不允许匿名用户上传。
anon_mkdir_write_enable=NO
设定不允许匿名用户建立目录。
idle_session_timeout=600
设定空闲连接超时时间。
data_connection_timeout=120
设定单次连续传输最大时间。
max_clients=10
设定并发客户端访问个数。
max_per_ip=5
设定单个客户端的最大线程数,这个配置主要来照顾Flashget、迅雷等多线程下载软件。
local_max_rate=50000
设定该用户的最大传输速率,单位b/s。
--------------------------------
这 里将原vsftpd.conf配置文件经过简化后保存作为虚拟用户配置文件的模版。这里将并不需要指定太多的
配置内容,主要的框架和限制交由 Vsftpd的主配置文件vsftpd.conf来定义,即虚拟用户配置文件当中没有
提到的配置项目将参考主配置文件中的设定。而在这里作为虚拟用户的配 置文件模版只需要留一些和用户流
量控制,访问方式控制的配置项目就可以了。这里的关键项是local_root这个配置,用来指定这个虚拟用户
的FTP主 路径。
5.更改虚拟用户的主目录的属主为虚拟宿主用户:
chown -R ftp.ftp /opt/vsftp/
6.检查权限:
ll /opt/vsftp/
总用量 4
drwxr-xr-x. 2 ftp ftp 4096 8月 14 09:25 test
六.给测试用户定制:
1.从虚拟用户模版配置文件复制:
cp /etc/vsftpd/vconf/vconf.tmp /etc/vsftpd/vconf/test
2.针对具体用户进行定制:
vi /etc/vsftpd/vconf/test
---------------------------------
local_root=/opt/vsftp/test
anonymous_enable=NO
write_enable=YES
local_umask=022
anon_upload_enable=NO
anon_mkdir_write_enable=NO
idle_session_timeout=300
data_connection_timeout=90
max_clients=1
max_per_ip=1
local_max_rate=25000
---------------------------------
七、配置本地账号
cp /etc/vsftpd/vconf/vconf.tmp /etc/vsftpd/vconf/user1
vi /etc/vsftpd/vconf/user1
---------------------------------
local_root=/home/user1
anonymous_enable=NO
write_enable=YES
local_umask=022
anon_upload_enable=NO
anon_mkdir_write_enable=NO
idle_session_timeout=600
data_connection_timeout=120
max_clients=5
max_per_ip=10
local_max_rate=60000
---------------------------------
八、防火墙和selinux设置
1. 防炎墙
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 20 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
/etc/init.d/iptables restart #最后重启防火墙使配置生效
2.selinux
vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq #保存,关闭。
reboot #重启系统
九、启动服务
Vsftpd的主程序/usr/sbin/vsftpd
启动脚本/etc/rc.d/init.d/vsftpd
设置自动启动 chkconfig –level 25 vsftpd on
十、关于 anonymous 用户
匿名用户主目录/var/ftp
注: /etc/vsftpd/vconf 及以下目录及文件的权限对root 具有可读权
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics