Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2350002
  • 博文数量: 609
  • 博客积分: 10061
  • 博客等级: 上将
  • 技术积分: 5920
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-25 08:30
文章分类

全部博文(609)

文章存档

2010年(13)

2009年(39)

2008年(558)

我的朋友

分类: LINUX

2008-08-14 16:22:14

 用 ProFTPD 构建 FTP 服务器(基于centos)

前  言

  FTP服务被广泛的应用着,常见的,一些大学、组织、机构等等,都有通过FTP服务器向外发布数据…但在这里,我们将要构建的FTP服务器将主要针对用于用户更新自己的网站。也就是说,让用户(root除外)只可以访问自己的Web目录(本站前面介绍的HTTP服务器构建中以public_html为例)。

  另外,为了避免通过平文传输时,数据被截获,从而泄漏隐私与密码,我们采用TLS方式,加密FTP传输过程中的数据,以确保安全。

(构建FTP服务器,您将有多种选择,比如通过vsftpd等等FTP服务器软件。但ProFTPD在一些方面,更能够符合我们的实际条件,尤其对于ADSL方式接入网络的服务器,ProFTPD能够很好的应对不断变化的IP地址造成的问题。)

安装 ProFTPD

  由于ProFTPD不存在于CentOS中yum的官方库中,所以用yum安装ProFTPD需要定义非官方的库。请先确认相应非官方库文件的存在。

[root@sample ~]# ls -l /etc/yum.repos.d/dag.repo  ← 确认相应库文件的存在性

-rw-r--r-- 1 root root 143 Oct 1 21:33 /etc/yum.repos.d/dag.repo ← 确认其存在(否则不能通过yum安装ProFTPD)

  如果以上,dag.repo文件不存在,则不能通过yum安装ProFTPD,需要定义非官方库。定义非官方库的方法请见 “CentOS的下载、安装及初始环境设置”一节中yum的相关设置。而且,在此前提下也要保证所定义的dag.repo文件的语法的正确性。

  然后,通过yum来在线安装ProFTPD。

[root@sample ~]# yum -y install proftpd  ← 安装ProFTPD

Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Reducing Dag RPM Repository for Red Hat Enterprise Linux to included packages only
Finished
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for proftpd to pack into transaction set.
proftpd-1.2.10-10.2.el4.r 100% |=========================| 15 kB 00:00
---> Package proftpd.i386 0:1.2.10-10.2.el4.rf set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
proftpd i386 1.2.10-10.2.el4.rf dag 699 k

Transaction Summary
=============================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 699 k
Downloading Packages:
(1/1): proftpd-1.2.10-10. 100% |=========================| 699 kB 00:03
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: proftpd ######################### [1/1]

Installed: proftpd.i386 0:1.2.10-10.2.el4.rf
Complete!

配置 ProFTPD

  然后,通过修改相应配置文件配置ProFTPD。

[root@sample ~]# vi /etc/proftpd.conf  ← 修改ProFTPD的配置文件

ServerType        standalone   ← 找到这一行,在行首添加“#”
 ↓
#ServerType        standalone   ← 变为此状态,不使用常驻模式

#ServerType       inetd   ← 找到这一行,去掉行首的“#”
 ↓
ServerType       inetd   ← 变为此状态,通过超级服务器来启动ProFTPD

DefaultRoot        ~ !adm   ← 找到这一行,将“ !adm”改为“/public_html !wheel”
 ↓
DefaultRoot        ~/public_html !wheel   ← 变为此状态,使除wheel组用户的根目录为public_html

找到TLS设置的语句群,如下:
# TLS
# Explained at
----------------------------------------------------------------
#TLSEngine         on
#TLSRequired        on
#TLSRSACertificateFile   /usr/share/ssl/certs/proftpd.pem
#TLSRSACertificateKeyFile /usr/share/ssl/certs/proftpd.pem
#TLSCipherSuite      ALL:!ADH:!DES
#TLSOptions        NoCertRequest
#TLSVerifyClient       off
##TLSRenegotiate     ctrl 3600 data 512000 required off timeout 300
#TLSLog           /var/log/proftpd/tls.log
----------------------------------------------------------------

 ↓将以上水平线间部分的语句,每行行首的“#”都去掉,变为下面水平线间的状态:

----------------------------------------------------------------
TLSEngine          on
TLSRequired         on  ← 只允许TLS方式的连接(如果将on改为off,普通方式也被允许)
TLSRSACertificateFile    /usr/share/ssl/certs/proftpd.pem
TLSRSACertificateKeyFile  /usr/share/ssl/certs/proftpd.pem
TLSCipherSuite       ALL:!ADH:!DES
TLSOptions         NoCertRequest
TLSVerifyClient       off
#TLSRenegotiate      ctrl 3600 data 512000 required off timeout 300
TLSLog            /var/log/proftpd/tls.log
----------------------------------------------------------------

然后在配置文件的末尾填如下几行:

ExtendedLog        /var/log/proftpd/access.log WRITE,READ default  ← 记录连接日志到相应日志文件
ExtendedLog        /var/log/proftpd/auth.log AUTH auth  ← 记录认证日志到相应日志文件
MasqueradeAddress    digeast.no-ip.info  ← 定义服务器域名
PassivePorts        50000 50030  ← 为PASV模式连接时指定端口号(1024以后存在的任意端口号)

  然后,为服务器建立证书。

[root@sample ~]# cd /usr/share/ssl/certs  ← 进入相应的目录

[root@sample certs]# make proftpd.pem  ← 建立服务器证书

umask 77 ; \
PEM1=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
PEM2=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
/usr/bin/openssl req -newkey rsa:1024 -keyout $PEM1 -nodes -x509 -days 365 -out $PEM2 ; \
cat $PEM1 > proftpd.pem ; \
echo "" >> proftpd.pem ; \
cat $PEM2 >> proftpd.pem ; \
rm -f $PEM1 $PEM2
Generating a 1024 bit RSA private key
.........++++++
............++++++
writing new private key to '/tmp/openssl.sG3126'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [GB]:CN  ← 输入国家简写
State or Province Name (full name) [Berkshire]:Hei Long Jiang  ← 输入省份
Locality Name (eg, city) [Newbury]:Harbin  ← 输入城市
Organization Name (eg, company) [My Company Ltd]:  ← 输入组织名(任意)
Organizational Unit Name (eg, section) []:  ← 直接回车跳过
Common Name (eg, your name or your server's hostname) []:   ← FTP服务器名反馈
Email Address []:yourname@yourserver.com  ← 输入E-mail地址

启动 ProFTPD

  启动之前,先对超级服务器的ProFTPD的启动脚本做一些修改。

[root@sample certs]# vi /etc/xinetd.d/xproftpd  ← 编辑ProFTPD启动脚本

log_on_success += DURATION USERID  ← 找到此行,将“DURATION USERID”改为“HOST PID”
 ↓
log_on_success += HOST PID   ← 变为此状态,防止登录时要等待30秒

log_on_failure += USERID  ← 找到此行,将“USERID”改为“HOST”
 ↓
log_on_failure += HOST   ← 变为此状态,防止登录时要等待30秒

disable = yes  ← 找到此行,将yes改为no
 ↓
disable = no   ← 变为此状态,让ProFTPD通过超级服务器启动

  然后,通过重新启动超级服务器间接启动ProFTPD。

[root@sample certs]# chkconfig xproftpd on  ← 设置ProFTPD自启动

[root@sample certs]# chkconfig --list xproftpd  ← 查看ProFTPD自启动

xproftpd on  ← 确认为on的状态就OK

[root@sample certs]# /etc/rc.d/init.d/xinetd restart  ← 重新启动超级服务器

Stopping xinetd:                [ OK ]
Starting xinetd:                 [ OK ]

连接到FTP服务器

  当我们成功的启动了FTP服务之后,就可以通过客户端软件连接到服务器进行文件的上传和下载了。但由于,本站介绍的方法,把安全、传输的保密性放在了第一位,这也就使得好多不支持TSL的FTP软件无法连接到服务器。支持TSL的FTP客户端软件,比较有代表性的有Staff-FTP, SmartFTP。本站将以SmartFTP为例(下一节),介绍如何从客户端通过FTP连接到服务器的方法。


阅读(1087) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~