| 在網際網路上面的傳輸協定當中,FTP(File Transfer Protocol)可說是最古老的協定之一了!早期還沒有這麼多好用的協定之前(例如SAMBA),都是使用FTP來進行資料的傳遞的呢!另外,一般來說資料的傳輸以FTP這個協定來傳送是相當的快速的,而且某些場合當中其實也相當的方便。不過,值得注意的是,使用FTP來傳輸時,其實是具有一定程度的『危險性』,因為資料在網際網路上面是完全沒有受到保護的『明碼』機制!所以鳥哥不太建議大家使用這個伺服器的啦!尤其當你建置好了FTP之後,如果經常進行資料的傳遞,對於您的網路頻寬『真的有很大的損害』啊!不過,無論如何,FTP仍然有其存在的必要!例如義守大學的FTP站就作的相當的棒啊!不過,FTP伺服器的危險性挺高的,因此我們選擇一個強調安全性的vsftpd軟體來架設喔! |



[root@linux ~]# cat /etc/pam.d/vsftpd #%PAM-1.0 auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd.ftpusers onerr=succeed auth required pam_stack.so service=system-auth auth required pam_shells.so account required pam_stack.so service=system-auth session required pam_stack.so service=system-auth |
[root@linux ~]# cat /etc/vsftpd.ftpusers # Users that are not allowed to login via ftp root bin daemon ....底下省略.... |
[root@linux ~]# /etc/init.d/vsftpd start [root@linux ~]# netstat -tulnp| grep 21 tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 11689/vsftpd # 看到囉,是由 vsftpd 所啟動的呢! |
[root@linux ~]# vi /etc/vsftpd/vsftpd.conf # 找到底下這一行:大約在 109 行左右啦! listen=YES # 將他改成這樣啊: listen=NO |
[root@linux ~]# vi /etc/xinetd.d/vsftpd
service ftp
{
socket_type = stream
wait = no
user = root
server = /usr/sbin/vsftpd
log_on_success += DURATION USERID
log_on_failure += USERID
nice = 10
disable = no
}
|
[root@linux ~]# /etc/init.d/vsftpd stop [root@linux ~]# /etc/init.d/xinetd restart [root@linux ~]# netstat -tulnp| grep 21 tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 32274/xinetd |
[root@linux ~]# vi /etc/vsftpd/vsftpd.conf # 底下鳥哥僅列出有設定的項目,若無設定時,請以您系統的 man 5 vsftpd.conf # 結果去搜尋預設值即可喔! # 1. 與匿名者有關的資訊: anonymous_enable=YES # 2. 與實體用戶有關的設定 local_enable=YES write_enable=YES local_umask=022 userlist_enable=YES # 3. 與主機有關的設定 dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES pam_service_name=vsftpd listen=YES tcp_wrappers=YES |
[root@linux ~]# vi /etc/vsftpd/vsftpd.conf # 在這個檔案當中加入這一句即可 use_localtime=YES .....底下省略..... [root@linux ~]# /etc/init.d/vsftpd restart |
[root@linux ~]# vi /etc/vsftpd/vsftpd.conf # 1. 與匿名者相關的資訊,在這個案例中將匿名登入取消: anonymous_enable=NO # 2. 與實體用戶相關的資訊 # 可寫入,且新增目錄、檔案權限為 775,因為 umask 為 002 嘛! local_enable=YES write_enable=YES local_umask=002 # 設定抵擋某些使用者登入的項目設定值!注意,底下的檔案必須存在! userlist_enable=YES userlist_deny=YES userlist_file=/etc/vsftpd.user_list # 3. 與主機有關的設定 use_localtime=YES dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES pam_service_name=vsftpd listen=YES tcp_wrappers=YES banner_file=/etc/vsftpd/welcome.txt [root@linux ~]# /etc/init.d/vsftpd restart |
[root@linux ~]# vi /etc/vsftpd/welcome.txt 歡迎光臨本小站,本站提供 FTP 的相關服務! 主要的服務是針對本機實體用戶提供的, 若有任何問題,請與鳥哥聯絡! |
[root@linux ~]# vi /etc/vsftpd.user_list root bin ....底下省略.... |
1. 測試使用已知使用者登入,例如 dmtsai 這個實體用戶: [root@linux ~]# ftp localhost Connected to localhost (127.0.0.1). 220-歡迎光臨本小站,本站提供 FTP 的相關服務! <==剛剛建立的歡迎訊息 220-主要的服務是針對本機實體用戶提供的, 220-若有任何問題,請與鳥哥聯絡! 220 Name (localhost:root): dmtsai <==登入者帳號! 331 Please specify the password. Password: <==輸入密碼,螢幕不會有任何訊息的顯示 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> bye 221 Goodbye. |
[root@linux ~]# vi /etc/vsftpd/vsftpd.conf # 增加是否設定針對某些使用者來 chroot 的相關設定呦! chroot_list_enable=YES chroot_list_file=/etc/vsftpd.chroot_list [root@linux ~]# /etc/init.d/vsftpd restart |
[root@linux ~]# vi /etc/vsftpd.chroot_list dmtsai bird1 |
[root@linux ~]# vi /etc/vsftpd/vsftpd.conf # 預設所有實體用戶被 chroot 而開放某些人可完整存取 (不 chroot) 的情況 chroot_local_user=YES chroot_list_enable=YES chroot_list_file=/etc/vsftpd.chroot_list [root@linux ~]# /etc/init.d/vsftpd restart |
[root@linux ~]# vi /etc/vsftpd.chroot_list nikky |
[root@linux ~]# vi /etc/vsftpd/vsftpd.conf # 增加底下這一個參數即可: local_max_rate=100000 [root@linux ~]# /etc/init.d/vsftpd restart |
[root@linux ~]# vi /etc/vsftpd/vsftpd.conf # 增加底下的這兩個參數: max_clients=10 max_per_ip=1 [root@linux ~]# /etc/init.d/vsftpd restart |
[root@linux ~]# vi /etc/vsftpd/vsftpd.conf # 這幾個參數必須要修改成這樣: userlist_enable=YES userlist_deny=NO userlist_file=/etc/vsftpd.user_list [root@linux ~]# /etc/init.d/vsftpd restart |
| 例題: 假設你因為某些特殊需求,所以必須要開放root使用FTP傳輸檔案,那麼你應該要如何處理? 答:
|
[root@linux ~]# mkdir /var/ftp/linux [root@linux ~]# mkdir /var/ftp/gnu |
[root@linux ~]# vi /etc/vsftpd/vsftpd.conf # 將這個檔案改成這樣: # 1. 與匿名者相關的資訊: anonymous_enable=YES # 不必提供密碼啦!可直接登入哩! no_anon_password=YES # 限制流速啦! anon_max_rate=30000 # 與連線時間有關的設定項目 data_connection_timeout=60 idle_session_timeout=600 # 限制連線人數 max_clients=50 max_per_ip=5 # 2. 與實體用戶相關的資訊,本案例中為關閉他的情況! local_enable=NO # 3. 與主機有關的設定 use_localtime=YES dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES pam_service_name=vsftpd listen=YES tcp_wrappers=YES banner_file=/etc/vsftpd/anon_welcome.txt [root@linux ~]# /etc/init.d/vsftpd restart |
[root@linux ~]# vi /etc/vsftpd/anon_welcome.txt 歡迎光臨本站所提供的 FTP 服務! 本站主要提供 Linux 作業系統相關檔案以及 GNU 自由軟體喔! 有問題請與站長聯絡!謝謝大家! 主要的目錄為: linux 提供 Linux 作業系統相關軟體 gnu 提供 GNU 的自由軟體 |
[root@linux ~]# ftp localhost Connected to localhost (127.0.0.1). 220-歡迎光臨本站所提供的 FTP 服務! <==同樣的,一些歡迎訊息 220-本站主要提供 Linux 作業系統相關檔案以及 GNU 自由軟體喔! 220-有問題請與站長聯絡!謝謝大家! 220-主要的目錄為: 220- 220-linux 提供 Linux 作業系統相關軟體 220-gnu 提供 GNU 的自由軟體 220 Name (localhost:root): anonymous <==一定得是這個匿名帳號 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> dir 227 Entering Passive Mode (127,0,0,1,94,56) 150 Here comes the directory listing. drwxr-xr-x 2 0 0 4096 Dec 18 17:37 gnu drwxr-xr-x 2 0 0 4096 Dec 18 17:37 linux drwxr-xr-x 2 0 0 4096 Aug 13 03:25 pub 226 Directory send OK. ftp> bye 221 Goodbye. |
[root@linux ~]# vi /etc/vsftpd/vsftpd.conf # 新增底下這幾行啊! write_enable=YES anon_other_write_enable=YES anon_mkdir_write_enable=YES anon_upload_enable=YES [root@linux ~]# /etc/init.d/vsftpd restart |
[root@linux ~]# mkdir /var/ftp/upload [root@linux ~]# chown ftp /var/ftp/upload |
[root@linux ~]# vi /etc/vsftpd/vsftpd.conf # 將這幾行給他改一改先! write_enable=YES anon_mkdir_write_enable=YES anon_upload_enable=YES chown_uploads=YES chown_username=root [root@linux ~]# /etc/init.d/vsftpd restart |
[root@linux ~]# vi /etc/vsftpd/vsftpd.conf # 增加底下這幾行即可啊! pasv_min_port=65400 pasv_max_port=65410 [root@linux ~]# /etc/init.d/vsftpd restart |




iptables -A INPUT -p TCP -i $EXTIF --dport 21 -j ACCEPT |
iptables -A INPUT -p TCP -i $EXTIF --dport 65400:65410 -j ACCEPT |
[root@linux ~]# vi /etc/hosts.allow vsftpd: 192.168.1.0/255.255.255.0 [root@linux ~]# vi /etc/hosts.deny vsftpd: ALL |
[root@linux ~]# vi /etc/xinetd.d/vsftpd
# vsftpd is the secure FTP server.
service ftp
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/sbin/vsftpd
server_args = /etc/vsftpd/vsftpd.conf
# 上面這個 server 的設定請依照您的主機環境來設定!
# 至於 server_args 則請寫入您的 vsftpd 的設定檔完整檔名即可!
per_source = 5 <==與同一 IP 的連線數目有關
instances = 200 <==同一時間最多的連線數目
no_access = 192.168.1.3
banner_fail = /etc/vsftpd/vsftpd.busy_banner
# 上面這個檔案就是當主機忙碌中,則在 Client 端顯示的內容!
log_on_success += PID HOST DURATION
log_on_failure += HOST
}
[root@linux ~]# vi /etc/vsftpd/vsftpd.conf
# 確定這個檔案內存在這個參數喔!
listen=NO
[root@linux ~]# vi /etc/vsftpd/vsftpd.busy_banner
421 很抱歉,伺服器現在上線人數過多,請待會兒再連線!
# 那個 421 是錯誤代碼哩!
[root@linux ~]# /etc/init.d/vsftpd stop
[root@linux ~]# /etc/init.d/xinetd restart
|