天天看點

ubuntu下安裝proftpd

    ProFTPD是一個Unix平台上或是類Unix平台上(如Linux, FreeBSD等)的FTP伺服器程式,

    它是在自由軟體基金會的版權聲明(GPL)下開發、釋出的免費軟體,也就是說任何人隻要遵

    守GPL版權聲明,都可以随意修改源始碼。  

    ProFTPD設計目标是實作一個安全且易于設定的FTP Server。目前Unix或類Unix平台上

    FTP Server十分有限,最常使用的恐怕就是wu-ftpd了。雖然wu-ftpd有着極佳的效能同時也是

    一套很好的軟體,然而它卻欠缺了許多Win32平台上FTP Server的一些特色,同時wu-ftpd過去

    也有不少的安全漏洞陸續被發現。ProFTPD的原創者本身就曾經花非常多的時間尋找wu-ftpd

    的漏洞加以改進并且增加許多功能。然而十分不幸的是,他很快地發現顯然wu-ftpd需要全部

    重新的改寫才能補足欠缺的設定能力以及缺乏的一些功能。ProFTPD不是從其它FTP Server的

    既有原始碼修改而産生的,相反的,它是完全獨立而完整、重新改寫的FTP Server。  

   ProFTPD的主要包括如下特點: 

* 單一主設定檔案,包含許多指令以及其支配的組,? 耆際侵憊鄣納瓒āH绻魑歡訟

pache Web Serve的設定不陌生的話相信一定會覺得十分容易操作設定。  

* 每個目錄都可以定義一個".ftpaccess"設定檔案,就如同Apache的".htaccess"檔案一樣可以設定

該目錄的存取權限。  

* 可設定多個虛拟FTP server,而匿名FTP服務更是十分容易。  

* 可根據系統的負載(load)選擇以單獨運作(stand-alone)方式或是由inetd啟動。  

* 匿名FTP的根目錄不需要特定的目錄結構、系統二進制執行檔案或其它系統檔案。  

* ProFTPD不執行任何外部程式以免造成安全漏洞。  

* 具有隐藏目錄或隐藏檔案,源自于Unix形式的檔案權限,或是user/group類型的檔案權限設定。  

* 能夠以一般使用者在單獨運作(stand-alone)模式下執行,以減少某些藉由攻擊方式取得root權的

可能性。注:此功能與Unix的作業系統有關。 

* 支援系統記錄以及utmp/wtmp。  

記錄的方式與wu-ftpd的标準完全相容,也支援記錄内容的延伸格式。  

* 支援Shadow&! nbsp;password,包括了帳号使用期限設定的功能。 

編譯和安裝  

    Proftpd提供了多種安裝格式,包括源代碼方式、RPM方式、deb方式(debian軟體包)等。本文

    主要讨論源代碼方式的安裝。 

    從ftp.proftpd.net下載下傳最新版本的proftpd-1.2.0rc3到Linux伺服器上。然後按照如下步驟

    進行處理: 

[[email protected] /]# cp proftpd-1.2.0rc3.tar.gz /usr/src/ 

[[email protected] /]# cd /usr/src 

[[email protected] src]# tar xvfz proftpd-1.2.0rc3.tar.gz 

[[email protected] src]# cd proftpd-1.2.0rc3 

[[email protected] proftpd-1.2.0rc3]# ./configure 

[[email protected] proftpd-1.2.0rc3]# make 

[[email protected] proftpd-1.2.0rc3]# make install 

    到現在為止,你已經完成了proftpd的編譯和安裝。并且在/usr/local/etc/目錄下有一個默

    認的proftpd配置檔案proftpd.conf。 

啟動測試 

    對于筆者的試驗系統RedHat6.2來說,需要将該配置檔案中: 

    Group nogrou! p 

修改為: 

    Group nobody 

    因為redhat系統中nobody使用者屬于nobody組,而不是nogroup組。 

    若需要将proftpd設定為系統啟動時自動啟動則通過如下指令拷貝啟動檔案: 

    [[email protected] proftpd-1.2.0rc3]# cp ./contrib/dist/rpm/proftpd.init.d /etc/rc.d 

/init.d/proftpd 

    然後修改該腳本的可執行屬性: 

    [[email protected] /]# chmod +x /etc/rc.d/init.d/proftpd 

    然後編輯/etc/rc.d/init.d/functions: 

    修改 

export PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin" 

    為 

export PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/sbin" 

注:若将在運作./cofigure指令時通過--prefix選項指定将proftpd安裝在/usr/sbin目! 錄下

則不需要修改fuctions檔案。 

然後運作指令: 

     [[email protected] rc3.d]# chkconfig --level 35 proftpd on 

則下次系統啟動以後,proftpd将自動啟動。 

    最後,需要確定系統目前沒有ftp伺服器在運作: 

    [[email protected] /]# netstat -ln 

    若輸出中不包含 

    tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 

    這樣的内容則可以直接啟動proftpd,否則需要關閉以前的ftpd伺服器。對于一般的預設

    Linux安裝來說,則需要通過以下的途徑來關閉ftp伺服器: 

    編輯/etc/inetd.conf檔案,在 

ftp stream tcp nowait root /usr/sbin/tcpd in.ftpd -l -a 

    一行前加上#: 

#ftp stream tcp nowait root /usr/sbin/tcpd in.ftpd -l -a 

    然後: 

[[email protected] ! /]# ps ax|grep inetd 

350 ? S 0:00 inetd  

    得到inetd的程序号 ,重新啟動inetd程序: 

        [[email protected] /]# kill -HUP 350    

    然後通過如下指令啟動proftpd: 

    [[email protected] /]# /etc/rc.d/init.d/proftpd start 

   這時候可以通過如下指令來測試proftpd是否正常運作:  

C:WINDOWS>ftp 192.168.2.33 

Connected to 192.168.2.33. 

220 ProFTPD 1.2.0rc3 Server (ProFTPD Default Installation)[ftpd.test.com.cn] 

User (192.168.2.33:(none)): ideal 

Password: 

230 User ideal logged in. 

ftp> 

則現在你就擁有了一個安全可靠的ftp伺服器。 

FAQ 

1、我安裝proftpd以後,出現了問題,我如何調試? 

通過通過指令! /usr/local/sbin/proftpd -d9 -n啟動proftpd來進行調試,則proftp d就會将

調試資訊列印到consle上以供調試之用。 

2、為什麼我的proftpf啟動以後,匿名使用者不能登入? 

        檢視proftp配置檔案/usr/local/etc/proftpd.conf,修改<Anonymous ~ftp>為

        <Anonymous /home/ftp>(這裡/home/ftp可以是任何希望匿名使用者登入以後的目前根目錄,

        但是確定要使該目錄允許ftp使用者通路),并且若<Anonymous /home/ftp>部分的User指令

        指定的使用者為ftp使用者,則需要在配置檔案中添加如下指令訓示: 

RequireValidShell off 

3、我如何實作一個正常使用者登入以後将其的通路限定在某個目錄之下? 

可以通過指令DefaultRoot來實作。例如若希望将ftpusers組的使用者限定在自己的home目錄下,則

需要首先建立該組: 

/usr/sbin/groupadd ftpusers 

然後将使用者ideal加入到該組中: 

usrmod -G ftpusers ideal 

最後在在proftpd.conf檔案中添加如下内容: 

DefaultRoot ~ ftpusers 

也可以限制使用者登入以後僅僅通路自己主目錄下的一個子目錄: 

Default! Root ~/anoftp ftpusers 

當然也可以将使用者限制在其他目錄之下,而不是自己的home目錄下: 

DefaultRoot /tmp ftpusers 

也可以限定一個使用者組的某些使用者被限制,而其他不作限制: 

DefaultRoot ~ ftpusers,!empolyee 

這個指令訓示僅僅限制ftpusers組中的不是empolyee組的使用者進行限制。 

4、我如何使使用者登陸時不顯示ftp伺服器版本資訊,以增強安全性? 

在proftpd.conf中添加如下内容: 

ServerIdent off 

則再次登入時,顯示如下内容: 

C:WINDOWS>ftp 192.168.2.33 

Connected to 192.168.2.33. 

220 ftpd.test.com.cn FTP server ready. 

User (192.168.2.33:(none)): 

5、在proftpd環境下如何設定虛拟主機? 

可以通過指令:VirtualHost來實作,一個最簡單的例子: 

<VirtualHost 192.168.2.35> 

ServerName "virtual FTP server" 

</VirtualHost> 

若你僅僅希望通過匿名通路某個虛拟主機,則使用如下! 的指令: 

<VirtualHost 192.168.2.35>  

Serv erName "virtual FTP server"  

<Limit LOGIN>  

DenyAll  

</Limit>  

<Anonymous /usr/local/private>  

User private 

Group private  

<Limit LOGIN>  

AllowAll  

</Limit> 

</Anonymous>  

</VirtualHost> 

這樣192.168.2.35的這台主機則僅僅允許匿名登入。 

筆者的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 &! quot;test.com.cn FTP Server" 

ServerType standalone 

DefaultServer on 

# Port 21 is the standard FTP port. 

Port 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&! nbsp;limit maximum number of processes per&nb sp;service 

# (such as xinetd) 

MaxInstances 30 

RequireValidShell off 

ServerIdent off 

# Set the user and group that the server normally runs at. 

User nobody 

Group nobody 

# Normally, we want files to be overwriteable. 

<Directory /*> 

AllowOverwrite on 

</Directory> 

# A basic anonymous configuration, no upload directories. 

<Anonymous /home/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> 

DefaultRoot ~ ftpusers 

<VirtualHost 192.168.2.35>  

ServerName "virtual FTP server"  

<Limit LOGIN>  

DenyAll  

</Limit>  

<Anonymous /usr/local/private>  

User private 

Group private  

<Limit LOGIN>  

AllowAll  

</Limit> 

</Anonymous>  

</VirtualHost>