用proftpd構建ftp服務器
用proftpd構建ftp服務器:
FTP服務被廣泛的應用著,常見的,一些大學、組織、機構等等,都有通過FTP服務器向外發(fā)布數(shù)據(jù)…但在這里,我們將要構建的FTP服務器將主要針對 用于用戶更新自己的網(wǎng)站。也就是說,讓用戶(root除外)只可以訪問自己的Web目錄(本站前面介紹的HTTP服務器構建中以public_html為 例)。
另外,為了避免通過平文傳輸時,數(shù)據(jù)被截獲,從而泄漏隱私與密碼,我們采用TLS方式,加密FTP傳輸過程中的數(shù)據(jù),以確保安全。
(構建FTP服務器,您將有多種選擇,比如通過vsftpd等等FTP服務器軟件。但ProFTPD在一些方面,更能夠符合我們的實際條件,尤其對于ADSL方式接入網(wǎng)絡的服務器,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的下載、安裝及初始環(huán)境設置”一節(jié)中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!
#p#
配置 ProFTPD
然后,通過修改相應配置文件配置ProFTPD。
- [root@sample ~]# vi /etc/proftpd.conf ← 修改ProFTPD的配置文件
- ServerType standalone ← 找到這一行,在行首添加“#”
- ↓
- #ServerType standalone ← 變?yōu)榇藸顟B(tài),不使用常駐模式
- #ServerType inetd ← 找到這一行,去掉行首的“#”
- ↓
- ServerType inetd ← 變?yōu)榇藸顟B(tài),通過超級服務器來啟動ProFTPD
- DefaultRoot ~ !adm ← 找到這一行,將“ !adm”改為“/public_html !wheel”
- ↓
- DefaultRoot ~/public_html !wheel ← 變?yōu)榇藸顟B(tài),使除wheel組用戶的根目錄為public_html
找到TLS設置的語句群,如下:
- # TLS
- # Explained at http://www.castaglia.org/proftpd/modules/mod_tls.html
----------------------------------------------------------------
- #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
----------------------------------------------------------------
↓將以上水平線間部分的語句,每行行首的“#”都去掉,變?yōu)橄旅嫠骄€間的狀態(tài):
----------------------------------------------------------------
- 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'
-----
- 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]:www.centospub.com ← 輸入組織名(任意)
- Organizational Unit Name (eg, section) []: ← 直接回車跳過
- Common Name (eg, your name or your server's hostname) []:www.centospub.com ← FTP服務器名反饋
- Email Address []:yourname@yourserver.com ← 輸入E-mail地址
#p#
啟動 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 ← 變?yōu)榇藸顟B(tài),防止登錄時要等待30秒
- log_on_failure += USERID ← 找到此行,將“USERID”改為“HOST”
- ↓
- log_on_failure += HOST ← 變?yōu)榇藸顟B(tài),防止登錄時要等待30秒
- disable = yes ← 找到此行,將yes改為no
- ↓
- disable = no ← 變?yōu)榇藸顟B(tài),讓ProFTPD通過超級服務器啟動
然后,通過重新啟動超級服務器間接啟動ProFTPD。
- [root@sample certs]# chkconfig xproftpd on ← 設置ProFTPD自啟動
- [root@sample certs]# chkconfig --list xproftpd ← 查看ProFTPD自啟動
- xproftpd on ← 確認為on的狀態(tài)就OK
- [root@sample certs]# /etc/rc.d/init.d/xinetd restart ← 重新啟動超級服務器
- Stopping xinetd: [ OK ]
- Starting xinetd: [ OK ]
連接到FTP服務器
當我們成功的啟動了FTP服務之后,就可以通過客戶端軟件連接到服務器進行文件的上傳和下載了。但由于,本站介紹的方法,把安全、傳輸?shù)谋C苄苑旁诹?***位,這也就使得好多不支持TSL的FTP軟件無法連接到服務器。支持TSL的FTP客戶端軟件,比較有代表性的有Staff-FTP, SmartFTP。本站將以SmartFTP為例(下一節(jié)),介紹如何從客戶端通過FTP連接到服務器的方法。