chapter 22 簡易 ftp server 架設 -- wu ftp
DESCRIPTION
Chapter 22 簡易 FTP Server 架設 -- Wu FTP. 22.1 原理. File Transfer Protocol ( FTP ) 進行 Server 端與 Client 端之間的檔案傳送的功能 以 TCP 封包的模式進行 Server 與 Client 之間的連線,當連線建立之後,使用者可以在 Client 端連上 Server 端進行檔案的下載與上傳. FTP 的功能. 不同等級的使用者身份,三種主要的身份 real user guest anonymous 命令記錄與登錄檔記錄 - PowerPoint PPT PresentationTRANSCRIPT
Chapter 22 簡易 FTP Server 架設 -- Wu FTP
22.1 原理
File Transfer Protocol ( FTP ) 進行 Server 端與 Client 端之間的檔案傳送的功
能 以 TCP 封包的模式進行 Server 與 Client 之間
的連線,當連線建立之後,使用者可以在 Client 端連上 Server 端進行檔案的下載與上傳
FTP 的功能
不同等級的使用者身份,三種主要的身份– real user– guest– anonymous
命令記錄與登錄檔記錄– syslogd daemon 進行資料的紀錄– 使用者下達過的命令與使用者傳輸資料的紀錄
限制或解除使用者家目錄所在– chroot (change root)
FTP 正常情況下的連線 主動模式 (active) 建立指令通道 (port 21)
– Client request (SYN) ftp-command port : 21
– Server response (SYN 與 ACK) – Client ACK
建立資料傳輸通道 (port 20)– Client request (SYN)
ftp-command port : 21– Server request (SYN)
ftp-data port : 20 – Client response (ACK)
Active mode
client FTP serverport 21 (ftp-command)
port 20 (ftp-data)
port > 1024
port > 1024
在 NAT 或者防火牆後端的 FTP Client 連線問題
•個人 PC 經過 NAT 主機連線•FTP Server 看到的 IP 是 NAT 主機的•FTP Server 主動由 port 20 向 NAT 主機的 >1024 port 要求建立連線 (Error)
Passive mode
建立指令通道 (port 21)– Same as active mode
建立資料傳輸通道 (port 20)– Client request (SYN)
ftp-command port : 21 告訴 FTP Server 使用 PASV 模式 (passive) 的方式來進行資料傳輸
– Server response Server 隨機選取一個大於 1024 的埠口,並經由命令通道告訴 client
端那個大於 1024 的埠口,開始等待 client 端的連線 – Client request (SYN)– Server response (ACK)
Passive mode
client FTP serverport 21 (ftp-command)
port 20 (ftp-data)
port > 1024
port > 1024
NAT server
22.2 套件安裝
rpm -qa | grep ftp ncftp-3.0.3-6
ftp-0.17-12 wu-ftpd-2.6.1-20
wu-ftpd – FTP 伺服器
ftp – ftp client 端工具
ncftp – 提供匿名登入的 FTP 網站的 client 端的連線 FTP 軟體
22.3 Server 端設定
1. Wu FTP 的結構 – 設定檔
/etc/ftpaccess /etc/ftpusers
– 檔案內的使用者都不能使用 FTP 的服務 /etc/ftphosts
– 允許或拒絕某部主機或者某位使用者是否能夠登入 FTP 主機 /etc/xinetd.d/wu-ftpd
– 啟動 FTP 的 daemon 設定檔案
Wu FTP 的結構
執行檔– ftpcount : 計算『目前連線的人數 – ftpwho : 顯示目前連線的使用者資訊 – ftprestart : 重新啟動 ftp – ftpshut : 指定時候關閉 FTP – in.ftpd : Wu FTP 的 daemon
用戶端的使用執行檔– ftp – ncftp
2. 最簡單的 ftpaccess 設定檔
1. 設定人物群組名稱 class < 人物群組名稱 > < 用戶身份 1, 用戶身份 2,..> < 允許連線的來源 >
class all real,guest,anonymous * class allone real,guest,anonymous *.edu.tw class alltwo guest,anonymous
!*.chinait.com !61.141.0.0/16 *
2. 設定 FTP 管理員的 e-mail 位址與主機名稱 email root@localhost
hostname vbird.adsldns.org
ftpaccess 設定檔 (Cont.)
3. 允許同一次連線當中,錯誤登入的次數 loginfails 5
4. 向使用者顯示 README 檔案的內容訊息 <readme> <README*> < 動作 > readme README* login readme README* cwd=*
– Login : 登入– cwd=* : 變換目錄
5. 將檔案的內容直接顯示在螢幕上面message /welcome.msg login message .message cwd=*
ftpaccess 設定檔 (Cont.)
6. 是否提供使用者線上立即執行的指令 < 指令名稱 > < 是否允許 /yes/no> < 針對的對象是誰 >
compress yes all tar yes all chmod no guest,anonymous delete no anonymous overwrite no anonymous rename no anonymous umask no all
ftpaccess 設定檔 (Cont.)
7. 將使用者執行的部分指令歷程記錄到 /var/log/xferlog<log> < 欲登錄的項目 > < 記錄的使用者身份 > < 何種動作 >
log transfers anonymous,guest,real inbound,outbound
ftpaccess 設定檔 (Cont.)
9. 匿名者的密碼驗證 <passwd-check> <no|trivial|rfc822> < 動作 >
no : 不需要密碼確認 trivial : 密碼當中必須含有 @ 這個 e-mail 的字元 rfc822: 密碼必須符合 frc822 的規範
– 動作 warn :使用者輸入錯誤密碼時僅顯示警告訊息,仍允許其登入 enforce :使用者輸入錯誤密碼,顯示警告訊息並中斷連線喔
passwd-check rfc822 warn
<deny-email>deny-email IE?0User@ deny-email mozilla@
ftpaccess 設定檔 (Cont.)
10. 設定允許與不許登入 FTP 伺服器的使用者與群組 deny-uid %-99 %65534- deny-gid %-99 %65534- allow-uid ftp allow-gid ftpdeny-uid testing testqq deny-uid 100-1000
3. Super daemon 管理 FTP
/etc/xinetd.d/wu-ftpd
service ftp { disable = no …… }
/etc/rc.d/init.d/xinetd restart netstat -tl ftp localhost
4. 歡迎畫面
message /welcome.msg login /welcome.msg
Welcome to my FTP site. Now is the time ==> %T The host name is %L You are %U and from %R There are %N person in my site, now. If you have any problem please call me %E
變數
%T 本地端主機時間– 格式為 Fri Mar 21 11:28:50 2003
%C 使用者目前所在的目錄 %R 遠端主機的 IP 或 hostname %L 本地端主機的名稱或 IP %E 系統管理員的 email %U 使用者的登入帳號名稱 %M FTP 主機所能允許的使用者最大連線數量 %N FTP 主機目前已經連線的使用者數量
5. 限制最大線上人數 etc/ftpaccess
<limit> < 群組名稱 > < 最大連線數 > < 時間 > < 顯示檔案 > limit all 20 Any /etc/ftpmaxnumberlimit guest 10 Any /etc/ftpmaxnumberlimit anonymous 5 Any0800-2000 /etc/ftpmaxnumber
/etc/ftpmaxnumber這裡已經太多人啦!請您等一下再進入! ^_^
6. 限制與取消使用者的家目錄
For real users /etc/ftpaccess
restricted-uid *
restricted-uid 200-400 test testing
unrestricted-uid test testing
7. 時間相關的設定項目 (/etc/ftpaccess)
timeout accept 120 – FTP daemon 等待 PASV 的連線時間 (client 回應 )
timeout connect 120 – 等待 client 端回應的 ACK
timeout data 2400 – FTP 可以讓我們下載或上傳一個檔案的最多時間
timeout idle timeout maxidle 1800
– 多久沒有動作會被踢掉 limit-time anonymous 30
limit-time guest 100– 一次連線內,多久會被強制斷線
8. 流量與上傳下載的限制項目 (/etc/ftpaccess) 整體檔案數目與檔案容量的限額
<file-limit> <in|out|total> < 數目或 bytes 數 > < 身份群組 > file-limit out 32 alltwodata-limit in 10240 alltwo
限制流量的方法<throughput> < 根目錄 > < 次目錄 > < 檔名 > <bytes/s> < 倍數 > < 位址 > throughput /var/ftp * * 10240 - * throughput /home/test /public_html * 51200 - * throughput /home/test /realdown * oo - *.vbird.org
10. anonymous 的根目錄與建立可上傳目錄
vi /etc/ftpaccess– anonymous-root /var/ftp– upload < 家目錄 > < 次目錄 > <yes|no> < 檔案所屬人 >
< 群組 > < 權限 > < 目錄 > upload /home/ftp/public /upload yes ftp sys 0666 upload /home/ftp/public /upfiles yes ftp sys 0666 nodirs
11. 針對人物的限制設定
real, guest, anonymous /etc/ftpaccess
nice < 數值 > < 使用者群組或身份 > defumask < 數值 > < 使用者群組或身份 > nice 10 anonymous nice -5 real defumask 022 real defumask 002 anonymous
12. 拒絕與開放某些使用者的登入
/etc/ftpaccess <deny> < 位址或主機名稱 > < 回覆給使用者訊息的文件 >
deny 192.168.0.100 /etc/ftpdeny.msg deny *.adsldns.org /etc/ftpdeny.msg
<deny-uid> < 帳號、 UID 或範圍 > deny-uid %-499 %65000- deny-gid %-499 %65000- allow-uid ftp allow-gid ftp
使用額外檔案來抵擋: /etc/ftphosts
<deny> < 使用者帳號 > < 不許連線的 IP 或主機名稱 >
<allow> < 使用者帳號 > < 不許連線的 IP 或主機名稱 > deny test 192.168.0.0/24 allow testing 192.168.1.0:255.255.255.0 deny test2 192.168.5.10 allow test2 *
14. 建立 passive port
/etc/ftpaccess <passive ports> <CIDR 位址 > < 最小 port> < 最大 port
>
<pasv-allow> < 人員身份 > < 位址 > passive ports 0.0.0.0/0 65501 65505
pasv-allow all *
Example
三個群組– real, guest, anonymous
real – 僅允許來自 140.116.0.0/16 網域
guest, anonymous– 允許來自所有網域,但不允許來自 61.141.0.0/16 網域
允許使用 passive ports– port number 為 65501 - 65510
小於 499 以及大於 65000 的 UID 與 GID 都被拒絕登入
Example
最大線上人數限制為 30 人– guest 最多 10 人, anonymous 最多為 5 人
實體用戶 mysiteuser – 被限制僅能在其家目錄當中工作,無法離開其家目錄
anonymous 登入者– 家目錄 : /var/ftp– 限制 anonymous 一次連線最久 10 分鐘– 最多僅能下載 20 個文件,以及 10MB 的資料量– 上傳僅允許上傳到 /var/ftp/upload – 預設檔案擁有者為 ftp ,群組是 sys
1. 使用者的帳號
groupadd myftpusers useradd -m -g myftpusers -s /sbin/nologin wwwus
er1 useradd -m -g myftpusers -s /sbin/nologin wwwus
er2 useradd -m -g myftpusers -s /sbin/nologin ftpuser passwd wwwuser1
2. /etc/ftpaccess 1. 針對 Server 的設定項目 針對群組的設定項目
class all real,guest,anonymous 140.116.0.0/16 class allreal real 140.116.0.0/16 class allguest guest !61.141.0.0/16 * class allanonymous anonymous !61.141.0.0/16 *
其他主機相關的設定項目 email [email protected] hostname tsai.adsldns.org shutdown /etc/shutmsg loginfails 3 log transfers anonymous,guest,real inbound,outbound passwd-check rfc822 warn
針對 Server 的設定項目 訊息管理
readme README* login readme README* cwd=* message /welcome.msg login message .message cwd=*
指令管理 compress yes all tar yes all chmod no guest,anonymous delete no anonymous overwrite no anonymous rename no anonymous
針對 Server 的設定項目
人物登入管理 deny-uid %-499 %65000- deny-gid %-499 %65000- allow-gid myftpusers
時間相關的設定值 timeout data 2400 timeout idle 1800 timeout maxidle 1800
主機最大連線人數設定 limit all 30 Any /etc/ftpmaxnumber
被動的 port 設定 passive ports 0.0.0.0/0 65501 65510
針對實體 , guest 用戶的設定
2. 針對實體用戶的設定restricted-uid mysiteuser
3. 針對 guest 用戶的設定limit allguest 10 Any /etc/ftpmaxnumberguestuser wwwuser1 wwwuser2 ftpuser
針對 guest 用戶的設定www users guest-root /home/wwwuser1/public_html wwwuser1 guest-root /home/wwwuser2/public_html wwwuser2 throughput /home/wwwuser1/public_html * * 102400 - * throughput /home/wwwuser2/public_html * * 102400 - *
FTP users guest-root /home/ftpuser ftpuser
針對 anonymous 用戶的設定
4. 針對 anonymous 用戶的設定limit allanonymous 5 Any /etc/ftpmaxnumber anonymous-root /var/ftp
limit-time anonymous 10
file-limit out 20 allanonymous
data-limit out 10000000 allanonymous
upload /var/ftp/upload yes ftp sys 0666
建立可上傳目錄與使用者家目錄
mkdir /var/ftp/upload chown ftp:sys /var/ftp/upload mkdir /home/wwwuser1/public_html mkdir /home/wwwuser2/public_html chown wwwuser1:myftpusers /home/wwwuser1/pu
blic_html chown wwwuser2:myftpusers /home/wwwuser2/pu
blic_html