proftpd配置和權限控制
1.初始配置文件
默认配置文件的位置为:
/usr/local/etc/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 "
ServerType
standalone
DefaultServer
on
# Port 21 is the standard FTP port.
Port 21
ServerType 指定FTP Server 的启动类型,一般使用standalone方式比较简单,如果访问量不大,为节省资源考虑用xinetd侦听启动,必须在这里指定。Port 指定FTP的侦听端口,一般使用21端口
# 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
Umask 指定FTP server 进程的Umask 值,022与Linux系统得默认值一致。
MaxInstances 指定 FTP server 的最大连接数。
# Set the user and group under
which the server will run.
User nobody
Group nogroup
# To cause every FTP user to be
"jailed" (chrooted) into their home
# directory, uncomment this line.
#DefaultRoot ~
DefaultRoot
User 和Group 指定proftpd 进程启动时的有效用户ID,处于安全考虑默认的身份是nobody,有一点要指出的是,一般Red Linux 9.0 中默认是没有nogroup 这个组的,把Group指定为nobody 即可。
DefaultRoot 选项限制Linux 系统用户通过FTP方式登录时将被限制在其home 目录下。
# Set the maximum number of seconds
a data connection is allowed
# to "stall" before being aborted.
#TimeoutStalled 300
AllowRetrieveRestart on
AllowStoreRestart on
# Normally, we want files to be overwriteable.
<Directory />
AllowOverwrite on
</Directory>
TimeoutStalled 指定一个连接的超时时间。
AllowRetriveRestart 和AllowStroeRestart 指定允许断点续传。
<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
DisplayFirstChdir .message
# Limit WRITE everywhere
in the anonymous chroot
<Limit WRITE>
DenyAll
</Limit>
</Anonymous>
这一部分,将在后面详细介绍。
2.配置文件结构分析#全局设置
设置项目1 参数1
设置项目2 参数2
#某个目录的设置
<Directory "路径名">
...
...
</Directory>
#关于匿名登陆的设置
<Anonymous "匿名登陆的目录">
...
...
<Limit 限制动作>
...
...
</Limit>
</Anonymous>
常用全局设置
DefaultRoot ~ # 限制每个FTP用户在自己的目录下,不可查看上一级目录
AllowRetrieveRestart on #下载时,允许断点续传
AllowStoreRestart on #上传时,允许断点续传
ServerIdent off #屏蔽服务器版本信息
TransferRate STOR|RETR 速度(Kbytes/s) user 使用者 #设定用户传输速率
MaxHostsPerUser 1 #每个帐户最多允许来源ip为1个, 对防止ftp账号还是比较有用的。
MaxClientsPerUser 1 #每个帐户在每个客户端最多可以同时登陆1次,可以防止多线程软件下载对服务器的破坏
MaxClientsPerHost 1 #同一个客户端只能最多1个账号可以登陆
WtmpLog on #是否要把ftp记录在日志中,如果不想可以设置成off屏蔽掉log日志。
TimeoutIdle 600 #客户端idle时间设置,默认就是600秒
DisplayLogin welcome.msg #设置ftp登陆欢迎信息文件
RootLogin on #允许root用户登录,默认是不允许的,安全起见不推荐此选项。
IdentLookups off #查找客户的远程用户名,关掉节省连接时间
欢迎词设置
关于欢迎文件的设置包含如下参数:
%T 目前的时间
%F 所在硬盘剩下的容量
%C 目前所在的目录
%R Client 端的主机名称
%L Server 端的主机名称
%U 使用者帐户名称
%M 最大允许连接人数
%N 目前的服务器连接人数
%E FTP服务器管理员的 email
%i 本次上传的文件数量
%o 本次下载的文件数量
%t 本次上传+下载的文件数量
知道这些参数,可以写出一个友好的欢迎语文件,例如:
欢迎您%U, 这是T-force的测试FTP服务器;
目前时间是:%T;
本服务器最多允许%M个用户连接数;
目前服务器上已有%N个用户连接数;
目前你所在的目录是%C;
目录所在的硬盘还剩下%F字节。
anonymous 配置块 在配置文件中anonymous配置块是非常重要的一部分,全局帐户的权限配置一般都由它来控制,下面分析一个比较常见的例子
# 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
#设定用户的别名
AnonRequirePassword on
#登陆需要密码
# 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
DisplayFirstChdir .message
# Limit WRITE everywhere
in the anonymous chroot
<Directory pub/*>
<Limit WRITE DELE RMD MKD READ>
DenyAll
</Limit>
<Limit STOR>
AllowAll
</Limit>
</Directory>
</Anonymous>
anonymous配置块中的重点是通过Limit对指定目录进行比较详尽的权限管理,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等权限,还是比较实用的
注:在测试是否可以下载时,不能用长度为0的空文件去测试,要用一个有内容的文件(文件大小不能为0k)。
针对上面这个Limit所应用的对象,又包括以下范围
AllowUser 针对某个用户允许的Limit
DenyUser 针对某个用户禁止的Limit
AllowGroup 针对某个用户组允许的Limit
DenyGroup 针对某个用户组禁止的Limit
AllowAll 针对所有用户组允许的Limit
DenyAll 针对所有用户禁止的Limit