上一篇简单的介绍了vsftpd的服务器安装配置,这次介绍一下Proftpd的安装配置,个人比较喜欢Proftpd的配置,较为干净利落。
1、下载源码包proftpd-1.3.5.tar.gz传到服务器
2、解压安装不多说了,注意一下./configure --prefix=/usr/local/proftpd
3、新建ftp帐户
useradd bonjour -d /var/www -M -s /sbin/nologin
chown -R bonjour /var/www
passwd bonjour
需要说明的是因为当时安装web服务器目录已经建立,所以增加-M参数;设置nologin是为了bash安全。
5、服务器简单配置
由于本人直接采用本地帐号使用ftp,匿名登录略过,可自行百度;
测试启动
/usr/local/proftpd/sbin/proftpd
抛出“Unknown Group错误”,打开配置文件(/usr/local/proftpd/etc/proftpd.conf),将Group下的nogroup换成nobody
然后就能启动了,可以用ps aux | grep ftp查看进程,netstat -ano | grep 21查看端口(记着打开防火墙的端口)
6、xinetd的安装和配置
yum install xinetd
cp contrib/dist/rpm/xinetd /etc/xinetd.d/proftpd
vim /etc/xinetd.d/proftpd
按照如图所示配置
然后就是配置proftpd.conf
# This is a basic ProFTPD configuration file (rename it to
# 'proftpd.conf' for actual use. It establishes a single server
# and a single anonymous login. It assumes that you have a user/group
# "nobody" and "ftp" for normal operation and anon.
ServerName "ProFTPD Default Installation"
ServerType standalone
DefaultServer on
# Port 21 is the standard FTP port.
Port 21
AllowRetrieveRestart on
AllowStoreRestart on
# Don't use IPv6 support by default.
UseIPv6 off
# Umask 022 is a good standard umask to prevent new dirs and files
# from being group and world writable.
Umask 022
# To prevent DoS attacks, set the maximum number of child processes
# to 30. If you need to allow more than 30 concurrent connections
# at once, simply increase this value. Note that this ONLY works
# in standalone mode, in inetd mode you should use an inetd server
# that allows you to limit maximum number of processes per service
# (such as xinetd).
MaxInstances 30
# Set the user and group under which the server will run.
User nobody
Group nobody
# To cause every FTP user to be "jailed" (chrooted) into their home
# directory, uncomment this line.
DefaultRoot /var/www
# Normally, we want files to be overwriteable.
AllowOverwrite on
# Bar use of SITE CHMOD by default
<Limit SITE_CHMOD>
DenyAll
</Limit>
<Limit LOGIN>
Order allow,deny
DenyUser !bonjour
</Limit>
<Directory /var/www>
<Limit WRITE>
AllowAll
</Limit>
</Directory>
# A basic anonymous configuration, no upload directories. If you do not
# want anonymous users, simply delete this entire <Anonymous> section.
#<Anonymous ~ftp>
# User ftp
# Group ftp
#
# # We want clients to be able to login with "anonymous" as well as "ftp"
# UserAlias anonymous ftp
#
# # Limit the maximum number of anonymous logins
# MaxClients 10
#
# # We want 'welcome.msg' displayed at login, and '.message' displayed
# # in each newly chdired directory.
# DisplayLogin welcome.msg
# DisplayChdir .message
#
# # Limit WRITE everywhere in the anonymous chroot
# <Limit WRITE>
# DenyAll
# </Limit>
#</Anonymous>
重启ftp服务
killall proftpd
由于FTP服务器默认是主动模式(Port模式)而非被动模式(PASV模式),浏览器输入ftp://XXXXX虽然能登录但是不能查看,
可以到windows命令行模式下输入ftp IP地址测试登录(dir指令查看目录下文件,如果文件看见了连接成功)
当然,最好还是用flashfxp来连接传输
更多信息请参考下面:
#全局设置
设置项目1 参数1
设置项目2 参数2
#某个目录的设置
<Directory “路径名”>
…
</Directory>
#关于匿名用户的设置
<Anonymous “匿名登陆的目录”>
…
<Limit 限制动作>
..
</Limit>
</Anonymous>
其中最重要的就是limit之中的部分,涉及到了具体的权限控制
CMD:Change Working Directory 改变目录
MKD:MaKe Directory 建立目录的权限
RNFR: ReName FRom 更改目录名的权限
DELE:DELEte 删除文件的权限
RMD:ReMove Directory 删除目录的权限
RETR:RETRieve 从服务端下载到客户端的权限
STOR:STORe 从客户端上传到服务端的权限
READ:可读的权限,不包括列目录的权限,相当于RETR,STAT等
WRITE:写文件或者目录的权限,包括MKD和RMD
DIRS:是否允许列目录,相当于LIST,NLST等权限,还是比较实用的
ALL:所有权限
LOGIN:是否允许登陆的权限
针对这些设置,又有如下具体的配置:
AllowUser 针对某个用户允许的Limit
DenyUser 针对某个用户禁止的Limit
AllowGroup 针对某个用户组允许的Limit
DenyGroup 针对某个用户组禁止的Limit
AllowAll 针对所有用户组允许的Limit
DenyAll 针对所有用户禁止的Limit
同时,可以针对单独的用户来限制速度
比如
<Limit STOR MKD> #允许上传和新建目录
AllowAll
</Limit>
我们还可以对ftp进行管理。所以在系统中建立一个用户,名称为ftpadmin,属于nogroup组,不允许登陆。同时赋予它对ftp所有的权限
<Anonymous /ftp/ftphome>
User ftpadmin
Group nogroup
<Directory *>
<Limit ALL>
AllowAll
</Limit>
</Directory>
</Anonymous>
启动不了,出现如下错误的解决方法
[root@new-host sbin]# ./proftpd
- IPv4 getaddrinfo 'new-host' error: Name or service not known
- warning: unable to determine IP address of 'new-host'
- error: no valid servers configured
- Fatal: error processing configuration file '/usr/local/proftpd/etc/proftpd.conf'
原因是无法绑定Ip地址。
在配置文件中增加下面这句:
DefaultAddress 192.168.8.105
再重启服务就可以了!
对出现的530 Login incorrect错误,查看日志发现Invalid shell错误
在配置中添加
RequireValidShell off 不要求有合法的shell
"Fatal: Socket operation on non-socket"
这通常意味着在 proftpd.conf 配置文件中 ServerType 指令被配置成 inetd
(超级服务器)方式而不是 standalone(独立服务器) 方式来运行
UseEncodingUTF-8 GBK 防止IE、资源管理器文件乱码神器
PathDenyFilter \.exe$ 限制上传的文件格式
# We don't want .ftpaccess or .htaccess files to be uploaded
PathDenyFilter "(\\.ftpaccess|\\.htaccess)$"
#开起全盘的写权限
<Directory />
AllowOverwrite on
AllowStoreRestart on
#允许FXP
# AllowForeignAddress on
<Limit All>
AllowAll
</Limit>
</Directory>
AuthAliasOnly on #只允许别名
./configure --with-modules=mod_quotatab:mod_quotatab_file:mod_ban:mod_tls:\
mod_rewrite:mod_ifsession --enable-ctrls --enable-nls
--with-modules //编译时包括选项:
mod_quotatab //启用 quota用户磁盘限额
mod_quotatab_file //采用基于文件的quotatab
mod_ban //启动动态黑名单,防止密码猜测,DDOS攻击
mod_tls //启用tls,实现功能FTPS
mod_rewrite //启用重写,可实现用户上传内容自动改名
mod_ifsession //启用会话判断,可判断会话,对用户IP设置规则。
--enable-ctrls //启用访问控制,可设置ACL
--enable-nls //启用语言探测,解决中文乱码。
make
//默认安装到/usr/local/ ,需要root权限
make install
##关闭欢迎信息显示
DeferWelcome off
##如果显示欢迎信息,则指定显示的文件
DisplayLogin welcome.msg
##指定切换文件夹时,显示的欢迎信息
DisplayChdir .message
#匿名用户默认客户端连接数为10,如果想在客户端连接数满时显示消息,就在MaxClents 10 后面加空格加你的提示消息”人满了,稍后你再来吧!”
#
##登录超时时间,从出现输入用户名的提示符到断开连接的时间
TimeoutLogin 1200
##空闲超时,无操作超时
TimeoutIdle 600
##不传输超时,数据连接建立,但是没有数据传输
TimeoutNoTransfer 900
##延迟超时,从数据连接建立到有数据传输最大延迟时间
TimeoutStalled 3600
##不使用DNS反查询
UseReverseDNS off #加快连接速度
##不使用RFC 1413协议反查用户信息,加快FTP访问速度
IdentLookups off
这个RFC 1413协议有兴趣可以Search
##下面一个,建议还是开启delay引擎,更安全。
为什么这么说呢?Proftpd在接受用户请求的时候,会查询用户列表,以确定是否有这个用户。如果有,还会查询黑名单列表,访问控制列表。这些查询都需要时间。所以,不同情况(服务器存在账户和不存在账户)下,从输入用户名到出现密码提示符之间的时间会有一个时间差值。这个时间很短,凭人无法感觉,但是计算机可以识别,通过对这个时间差进行分析,可以试探那些Proftpd上存在哪些用户,不存在哪些用户。开启delay引擎,会均衡这个时间段。无论输入的用户存不存在,从用户名输入到弹出密码提示符的时间间隔都是一样的。