天天看點

ProFTPD部署指南

 ProFTPD部署指南

伺服器環境:RHEL5.4

下載下傳ProFTP:

# wget ftp://ftp1.hk.proftpd.org/proftpd/distrib/source/proftpd-1.3.4a.tar.bz2

1.FTP要求:

  公司四個部門:運維部、開發部、銷售部、行政部

  各部門使用者通路FTP後可以看到所有目錄,僅可以通路本部門的目錄

  需要FTP日志功能

  FTP認證方式基于檔案認證方式

  共享目錄:/var/ftp

2.解壓檔案:

# tar  -xjf   proftpd-1.3.4a.tar.bz2  -C /usr/src/

# cd  /usr/src/proftpd-1.3.4a/

安裝前請先閱讀INSTALL與README檔案

3.安裝ProFTPD:

#./configure  --help 檢視幫助選項

######################################################################################

以下為部分選項說明:        

--prefix=PREFIX 指定安裝路徑(--prefix=/usr/local/)        

--sysconfdir=DIR        指定FTP服務配置檔案路徑(--sysconfdir=/etc)        

--localstatedir=DIR     指定運作狀态的檔案存放位置(預設/var/proftpd)        

--with-modules=mod_ldap 指定加載功能子產品        

--enable-memcache       支援緩存功能        

--enable-nls            支援多語言環境(如中文),安裝完成後在主配置檔案中需要指定字元編碼(UseEncoding UTF-8 CP936)  

--enable-openssl        支援TLS加密FTP服務        

--enable-shadow 支援使用/etc/shadow驗證使用者密碼        

######################################################################################################

注:需要GCC編譯器

#./configure  --prefix=/usr/local/proftpd  --sysconfdir=/etc/  --enable-nls  --enable-openssl  --enable-shadow

#make

#make  install

#PATH=echo$PATH:/usr/local/proftpd/bin 添加環境變量

#useradd  -M -s /sbin/nologin  proftp

建立啟動使用者及組(該使用者無法登入系統,沒有宿主目錄)

4.建立共享目錄,修改配置檔案:

#mkdir  -p  /var/ftp/{運維部,開發部,銷售部,行政部}

#useradd -M -s /sbin/nologin  yunwei

#useradd -M -s /sbin/nologin  kaifa

#useradd -M -s /sbin/nologin  xiaoshou

#useradd -M -s /sbin/nologin  xingzheng

#chmod 777  /var/ftp/運維部

#chmod 777  /var/ftp/開發部

#chmod 777  /var/ftp/銷售部

#chmod 777  /var/ftp/行政部

#vim  /etc/proftpd.conf     以下為配置檔案原文(行号僅為參考值)

******************************************************************************************************

     1 # This is a basic ProFTPD configuration file (rename it to 

     2 # 'proftpd.conf' for actual use.  It establishes a single server

     3 # and a single anonymous login.  It assumes that you have a user/group

     4 # "nobody" and "ftp" for normal operation and anon.

     5

     6 ServerName "ProFTPD Default Installation"

                                         用戶端連接配接後顯示的字元

     7 ServerType standalone

                                         服務啟動模式

     8 DefaultServer on

     9

    10 # Port 21 is the standard FTP port.

    11 Port 21 端口

    12

    13 # Don't use IPv6 support by default.

    14 UseIPv6 off 禁用IPv6

    15

    16 # Umask 022 is a good standard umask to prevent new dirs and files

    17 # from being group and world writable.

    18 Umask 022     權限掩碼

    19

    20 # To prevent DoS attacks, set the maximum number of child processes

    21 # to 30.  If you need to allow more than 30 concurrent connections

    22 # at once, simply increase this value.  Note that this ONLY works

    23 # in standalone mode, in inetd mode you should use an inetd server

    24 # that allows you to limit maximum number of processes per service

    25 # (such as xinetd).

    26 MaxInstances 30      并發程序30個(防DoS攻擊)

    27

    28 # Set the user and group under which the server will run.

    29 User nobody  啟動服務的使用者

    30 Group nobody  啟動服務的組

    31

    32 # To cause every FTP user to be "jailed" (chrooted) into their home

    33 # directory, uncomment this line.

    34 #DefaultRoot ~ 共享根目錄(預設為使用者家目錄)

    35

    36 # Normally, we want files to be overwriteable.

    37 AllowOverwrite on 是否允許使用檔案覆寫權限

    38

    39 # Bar use of SITE CHMOD by default

    40 <Limit SITE_CHMOD> 權限設定

    41   DenyAll

    42 </Limit>

    43

    44 # A basic anonymous configuration, no upload directories.  If you do not

    45 # want anonymous users, simply delete this entire <Anonymous> section.

    46 <Anonymous ~ftp>

    47   User ftp

    48   Group ftp

    49

    50   # We want clients to be able to login with "anonymous" as well as "ftp"

    51   UserAlias anonymous ftp 使用者别名

    52

    53   # Limit the maximum number of anonymous logins

    54   MaxClients 10         最大用戶端連接配接數

    55

    56   # We want 'welcome.msg' displayed at login, and '.message' displayed

    57   # in each newly chdired directory.

    58   DisplayLogin welcome.msg 顯示登入資訊

    59   DisplayChdir .message

    60

    61   # Limit WRITE everywhere in the anonymous chroot

    62   <Limit WRITE> 權限設定

    63     DenyAll

    64   </Limit>

    65 </Anonymous>

該檔案格式:

##########################################################################

#   全局設定 參數值                                                   #

#                                                                        #

#   <Directory  "路徑"> 指定路徑相關設定,可以使用Limit文法限制目錄權限  #

#         ... ...                                                        #

#   ... ...                                                        #

#   </Directory>                                                         #

#                #

#  #

#   <anonymouse "路徑"> 匿名共享路徑相關設定(包括權限設定)     #

#   </anonymouse>          #

Limit權限說明:

#########################################################################

# CWD  : Change Working Directory 進入該目錄  #

# MKD  : Make Directory 建立目錄 #

# RNFR : Rename from 更名 #

# DELE : Delete 删除檔案 #

# RMD  : Remove Directory 删除目錄 #

# READ :  可讀         #

# WRITE:  可寫 #

# STOR :  可上傳 #

# RETR :  可下載下傳         #

# DIRS : 允許列出目錄 #

# LOGIN: 允許登入 #

# ALL  :  全部 #

修改後有效的配置檔案内容,部分内容為添加内容(#開始的部分為注釋):

     9  UseEncoding UTF-8 CP936 支援的編碼格式(中文)

    11 Port 21

    12  AllowRetrieveRestart on    允許斷點繼傳(上傳)

    13  AllowStoreRestart on    允許斷點繼傳(下載下傳)

    14 UseIPv6 off

    18 Umask 022

    19  RootLogin off 禁止root登入ftp

    26 MaxInstances 30

    27  SystemLog /var/log/proftp.log

                                                 産生獨立的日志檔案

    28 TransferLog /var/log/proftp.log

                                                 記錄使用者下載下傳的日志資訊

 #####如果想指定自己的日志格式可以結合(ExtendLog,LogFormat)兩個選項設定

    29 User proftp   設定啟動使用者為proftp

    30 Group proftp   設定啟動組為proftp

    34 DefaultRoot /var/ftp   指定共享根目錄為/var/ftp

    37 AllowOverwrite on

    46 #<Anonymous ~ftp> 該部分全部#注釋,取消匿名通路功能

    47 #  User ftp

    48 #  Group ftp

    51 #  UserAlias anonymous ftp

    54 #  MaxClients 10

    58 #  DisplayLogin welcome.msg

    59 #  DisplayChdir .message

    62 #  <Limit WRITE>

    63 #    DenyAll

    64 #  </Limit>

    65 #</Anonymous>

以下内容為設定權限,為手動添加内容

           所有使用者可以看到所有部門的檔案夾,僅可以通路自己部門的目錄

*****************************************************************************************************

    67  RequireValidShell off 使用者登入是否需要shell(對虛拟使用者很重要)

    68  AuthUserFile /usr/local/proftpd/ftpd.passwd

                          通過檔案認證使用者登入,需要ftpasswd指令建立該檔案

    69 <Directory "/var/ftp/*">

    70 <Limit CWD READ>  允許所有人可以檢視根目錄

    71 AllowAll

    72 </Limit>

    73 </Directory>

    74 <Directory "/var/ftp/運維部">

    75 <Limit CWD MKD RNFR READ WRITE STOR RETR>

    76 DenyAll  拒絕所有人往該目錄下執行Limit後的操作指令

    77 </Limit> 

    78 <Limit DELE>

    79 DenyAll  禁止任何人在該目錄下删除檔案

    80 </Limit>

    81 <Limit CWD MKD RNFR READ WRITE STOR RETR>

    82 AllowUser yunwei 僅允許yunwei使用者可以執行Limit後的所有指令

    83 </Limit> 

    84 </Directory>

    85 <Directory "/var/ftp/開發部">

    86 <Limit CWD MKD RNFR READ WRITE STOR RETR>

    87 DenyAll

    88 </Limit> 

    89 <Limit DELE>

    90 DenyAll

    91 </Limit>

    92 <Limit CWD MKD RNFR READ WRITE STOR RETR>

    93 AllowUser kaifa

    94 </Limit> 

    95 </Directory>

    96 <Directory "/var/ftp/行政部">

    97 <Limit CWD MKD RNFR READ WRITE STOR RETR>

    98 DenyAll

    99 </Limit> 

   100 <Limit DELE>

   101 DenyAll

   102 </Limit>

   103 <Limit CWD MKD RNFR READ WRITE STOR RETR>

   104 AllowUser xingzheng

   105 </Limit> 

   106 </Directory>

   107 <Directory "/var/ftp/銷售部">

   108 <Limit CWD MKD RNFR READ WRITE STOR RETR>

   109 DenyAll

   110 </Limit> 

   111 <Limit DELE>

   112 DenyAll

   113 </Limit>

   114 <Limit CWD MKD RNFR READ WRITE STOR RETR>

   115 AllowUser xiaoshou

   116 </Limit> 

   117 </Directory>

5.建立虛機帳号

ftpasswd指令格式說明

(該指令可以建立使用者檔案、組檔案,預設建立的使用者檔案為ftpd.passwd):

--passwd  建立密碼檔案,即AuthUserFile指定的檔案

--group   建立組檔案

--name   指定建立的使用者名

--uid   指定使用者虛拟UID

--gid     指定虛拟GID

--home   指定使用者家目錄

--shell   指定使用者Shell

--file   指定建立的檔案名

#ftpasswd  --passwd  --name=yunwei  --uid=1000  --home=/home/nohome  --shell=/bin/false

6.啟動FTP服務:

#/usr/local/proftpd/sbin/proftpd

成功驗證!!!!

這裡僅以使用者為實驗環境,需要實作組功能的情況可以自行探索...

支援開源

本文轉自丁丁曆險51CTO部落格,原文連結:http://blog.51cto.com/manual/760048 ,如需轉載請自行聯系原作者

繼續閱讀