首页  ·  知识 ·  基础设施
linuxFTP服务器的安装及管理
佚名  本站原创  数据中心  编辑:dezai  图片来源:网络
说明:因时间关系,没有对具体细节作详细说明,请参考wu-ftpFAQ以及ftpd,ftpaccess的在线文档(manftpd).一.&nb
说明: 
因时间关系,没有对具体细节作详细说明,请参考wu-ftp FAQ以及ftpd,ftpaccess 
的在线文档(man ftpd). 

一. ftp服务器 
1. inetd配置文件或xinetd.conf配置文件 
/etc/inetd.conf文件内容如下: 
ftp stream tcp nowait root /usr/sbin/tcpd in.ftpd -l -a 

/etc/xinetd.conf文件内容如下: 
service ftp 

socket_type = stream 
protocol = tcp 
wait = no 
user = root 
#only_from = 202.118.66.0 
#only_from += 192.168.1.2 
#only_from += localhost 
server = /usr/sbin/in.ftpd 
server_args = -l -a 



相关文件:/etc/services 
ftp-data 20/tcp 
ftp 21/tcp 

2. ftp用户(Anonymous FTP服务器需要用到) 
文件:/etc/passwd和/etc/shadow 

/etc/passwd: 
ftp:x:500:50:Anonymous FTP User:/home/ftp:/bin/false 

/etc/shadow: 
ftp:*:10689:0:99999:7::: 

$finger ftp 
Login: ftp Name: FTP User 
Directory: /home/ftp Shell: /bin/false 
Never logged in. 
No mail. 
No Plan. 

3. DNS配置 
ftp IN CNAME officail.domain.name. 

4. 管理员邮件别名 
文件: /etc/mail/aliases (Solairs) 
/etc/aliases (Linux) 
(egrep aliases /etc/mail/sendmail.cf ) 

ftp-admin: real-user-name@domain.name 

相关命令: newaliases, 建立邮件别名 


二. 文件系统结构 
1. Anonymous FTP 目录结构 
如下子目录: 
bin(ls,gzip,tar等anonymous ftp用户所要使用的二进制可执行文件) 
etc(passwd,group) 
lib(动态连接库,ld-2.0.7.so, ld-linux.so.2, ldd ../bin/ls 等) 
pub(可下载文件) 

2. passwd及group文件 
不要使用系统的passwd及group文件,最好只放所需的用户及组信息 
passwd文件: 
ftpadm:x:0:0:Anonymous FTP:/home/ftp:/bin/false 
ftp:x:60000:60000:Anonymous FTP:/home/ftp:/bin/false 
group文件: 
ftpadmin:x:0: 
ftp:x:60000: 

3. 文件及目录属性 
主目录/home/ftp 属主root, 属性555 
bin 属主root 组wheel或other, 属性111 
etc 同上 
lib 属主root, 属性555 
pub 属主为root或ftp管理员,属性555 

确认不要用ftp作任何文件或目录的属主! 

[hbwork@helius /etc]$ cd /home/ftp/ 
[hbwork@helius ftp]$ ls -l 
total 4 
d--x--x--x 2 root root 1024 Apr 8 17:57 bin 
d--x--x--x 2 root root 1024 Jun 4 15:12 etc 
drwxr-xr-x 2 root root 1024 Apr 8 17:57 lib 
dr-xr-sr-x 2 root ftp 1024 Apr 8 11:18 pub 

$ls -l bin 
[root@helius ftp]# ls -l bin/ 
total 250 
---x--x--x 1 root root 15236 Apr 28 1998 compress 
---x--x--x 1 root root 46356 Sep 11 1998 cpio 
---x--x--x 1 root root 45436 Sep 11 1998 gzip 
---x--x--x 1 root root 29980 Sep 11 1998 ls 
---x--x--x 1 root root 110668 Sep 11 1998 tar 
lrwxrwxrwx 1 root root 4 May 19 16:48 zcat -> gzip 

$ls -l etc 
total 19 
-r--r--r-- 1 root root 57 Jun 4 15:12 group 
-r--r--r-- 1 root root 16372 Sep 11 1998 ld.so.cache 
-r--r--r-- 1 root root 83 Jun 4 15:12 passwd 

(在Solaris上建立anonymouse FTP特殊一些,请参考Wu-ftpd-faq) 


4. 可选目录 
incoming Owner: root Mode:1733 (chmod 1733 incoming) 

三. 测试及调试 
egrep ftp /etc/inetd.conf 
ps ax |egrep inetd 
kill -HUP $PID 

$ftp localhost (or ftp 0) 
执行ls cd get 等指令看一下结果如何 


四. wu-ftpd FTP服务器进程 

增强功能: 
. 允许根据用户的ip地址或主机,用户名设置不同的类 
. 根据设置的类,管理员可以控制其访问权限,如防止anonymous用户 
删除文件或覆盖已有的文件 
. 可以实现自动执行uncompress,compress,tar,gzip等功能 
. 可以记载所有的upload/download,及ftp client所发送的每个命令. 
. 允许平滑关掉ftp服务器 

相关配置文件: 
ftpaccess 
ftpconversions 
ftphosts 
ftpuser 

相关命令: 
strings /usr/sbin/in.ftpd |egrep ftpaccess 

1. 编译 wu-ftpd 

最新版本: wu-ftpd-2.5.0 
ftp://ftp.dlut.edu.cn/pub/unix/ftp/servers/ 

$tar -zxvf wu-ftpd-2.5.0.tar.gz 
$cd wu-ftpd-2.5.0 
建议在编译安装之前参考文件INSTALL,README,upload.configuration.HOWTO 
如想定制自己的wu-ftpd,可编辑文件src/pathnames.h 
$build help 
查看编译帮助 

$./build lnx 
$su 
#./build install 

2. 命令行选项 
-d Sends debugging information to syslog 
-a Enable the use of the ftpaccess file(This is the default) 
-A Disable the use of the ftpaccess file 
-L Cause ftpd to log all USER commands. 
-i Causes ftpd to log all incoming(upload) file in the xferlog 
file( See pathnames.h ) 
-o Causes ftpd to log all outgoing(download) files in the xferlog file 

3. 文件ftpconversions 
doc/examples/, 用于指定get时的实时压缩或展开(on-the-fly). 

此文件不般情况下不用作修改 

4. ftpaccess 
(1)定义类 
三种用户类型: real anonymous 
guest(需要提供相应的口令) 
格式: 
class classname type[,type,...] address [ address ...] 

示例: 
class local real *.dlut.edu.cn 202.118.66 localhost 
class anonymous anonymous * 


(2)拒绝访问 
deny *.net.cn /etc/ftpmsgs/msg.denied 

(3)限制访问 
limit class number times messages 

limit anonymous 200 SaSu 
limit anonymous 100 Any /etc/ftpmsgs/msg.toomany 


loginfails 2 
tar no anonymous 
compress no anonymous 

chmod yes|no type [type ...] 
delete yes|no type [type ...] 
overwrite yes|no type [type ...] 
rename yes|no type [type ...] 
umask yes|no type [type ...] 

passwd-check none|trivial|rfc822 enforce|warn 

(5)banner 
显示在用户login之前的信息 
banner /etc/ftpmsg/banner.msg 

其中banner.msg文件中可以引用如下变量: 
%C Current working directory 
%E Email address of the administrator( email ftpadm@dlut.edu.cn) 
%F 可当目录下可用空间 
%L hostname 
%M 最大允许连接数 
%N 同一类中当前连接数 
%R The client host'name or ip address 
%T Current local time 
%U The name the user specified at login 

示例文件: 
Welcome to this test FTP Archive, running on %L. 

Please contact %E with any technical problems you may have 
accessing this archive. 

You are currently user %N out of a maximum %M users. It's 
%T in PRC. 

(6)message命令 
message pathname login 
message pathname cwd=dir 
message .conents cwd=* 
每改变目录均显示,cwd=dir只在第一次更改时显示 

(7)readme命令 
readme pathname [login|cwd=dir] [class] [class] 

readme README* cwd=* 

(8)shutdown命令 (2.5.0上不正常) 
shutdown pathname 

(9)log命令 

log commands type [ type ...] 

log transfer type [type ...] direction[,direction] 

(10)alias 
alias source: /pub/local/sw/source 

(11)cdpath 
cdpath /pub /pub1 

上载控制 
upload hierarchy directory yes|no owner group mode [dirs|nodirs] 

下面的wu-ftpd-2.5.0 /etc/ftpaccess文件中的upload配置(大家可以试一下大工FTP 
服务器的upload,但别传没用的过大的文件) 

# FTP-home-dir archiv-dir allow? owner group mode dirs? 
# (as in /etc/passwd) 

upload /home/ftp * no 
upload /home/ftp /pub3/incoming/windows yes ftpadmin ftp 0664 dirs 
upload /home/ftp /pub3/incoming/windows/* yes ftpadmin ftp 0664 dirs 
upload /home/ftp /pub3/incoming/unix yes ftpadmin ftp 0666 dirs 
upload /home/ftp /pub3/incoming/unix/* yes ftpadmin ftp 0666 dirs 
upload /home/ftp /pub3/incoming/other yes ftpadmin ftp 0666 dirs 
upload /home/ftp /pub3/incoming/other/* yes ftpadmin ftp 0666 dirs 
upload /home/ftp /pub3/incoming/WDI yes ftpadmin ftp 0666 dirs 
upload /home/ftp /pub3/incoming/WDI/* yes ftpadmin ftp 0666 dirs 


5. ftphosts文件 
allow ftp *.dlut.edu.cn 
allow anonymous *.dlut.edu.cn 
deny ftp *.dlmu.edu.cn 
deny ftp *.dlmu.edu.cn 202.118.80.* 


6.实用程序 

ftpcount 
ftpwho 
ftushut 

维护: 
建立连接时最好使用相对路径。 
根据软件类别建立不同的子目录。 
最好在每个目录中建立相应的说明文件或index文件,方便用户查找。 
本文作者:佚名 来源:本站原创
CIO之家 www.ciozj.com 微信公众号:imciow
    >>频道首页  >>网站首页   纠错  >>投诉
版权声明:CIO之家尊重行业规范,每篇文章都注明有明确的作者和来源;CIO之家的原创文章,请转载时务必注明文章作者和来源;
延伸阅读
也许感兴趣的
我们推荐的
主题最新
看看其它的