close
架過很多次了,但每次總有幾張鐵板一直踢到...所以決定把紀錄留下來,避免到時候又忘了...
- 練習用的FTP站規劃:
- 架設一個有登入網域限制的FTP站(允許192.168.1.0/24)。
相關檔案:/etc/proftpd/proftpd.conf, /etc/xinetd.d/proftpd
- 開放兩個帳號(ftpuser1, ftpuser2),但不允許實體用戶(Real User)及匿名用戶(Anonymous)登入。
相關檔案:/etc/proftpd/proftpd.conf, /etc/proftpd.passwd, /etc/proftpd.group
- 埠號(port)設定為1226。
相關檔案:/etc/proftpd/proftpd.conf, /etc/services
- 架設一個有登入網域限制的FTP站(允許192.168.1.0/24)。
- 發行版:
- Linux Ubuntu 2.6.32-33
- 重要檔案說明:
- /etc/proftpd/proftpd.conf
這就是ProFTPD主要設定檔,裡面包山包海管很大。
- /etc/services
裡面紀錄著各種service常用的埠號,如果你的service要用其他埠號,就要來這裡確認不會佔用到其他service的埠號,並把原service的設定註解掉,最後在# Local service下方新增你要用的service名稱及埠號。不要去改service名稱,否則ftp就算可以登入,進入passive mode後也無法順利連線!
- /etc/xinetd.d/proftpd
(自行創建)xinetd(super daemon)將會按照此設定檔的內容來啟動ProFTPD。務必使本檔內的service名稱與/etc/services中所列的名稱一致,否則會出現「找不到可用的service port」的錯誤訊息(見/var/log/syslog)。
- /etc/proftpd.passwd
(自行用ftpasswd(shell script)創建,Optional)如果你要使用Virtual User來使用FTP,要用這個檔案來放User資訊,暫時代替passwd。
- /etc/proftpd.group
(自行創建ftpasswd,Optional)如果你要使用Virtual User來使用FTP,要用這個檔案來放Group資訊,暫時代替group。
- /etc/ftpusers
禁用FTP的用戶名單,倘若以所列之帳號登入會被拒絕連線。本教學不更動此檔案,而在proftpd.conf中加入對應的AuthUserFile, AuthGroupFile與AuthOrder參數亦可達到相同效果!
- /etc/proftpd/proftpd.conf
- 步驟:
- 安裝xinetd及ProFTPD:
為求方便&不在意反應速度,我想要用xinetd來管理proftpd(也就是用super daemon管daemon),因此安裝proftpd時,請選擇inetd,而非standalone,我用Synaptic依序安裝好xinetd及proftpd之後,
- 先設定好Virtual user及Virtual Group:
# 查詢ftp這個user的uid及其group的gid
$ cat /etc/passwd | grep ftp
ftp:x:118:65534::/home/ftp:/bin/false
$ cat /etc/group | grep 65534
nogroup:x:65534:
# 建立ftpuser1及ftpuser2的在FTP的家目錄
$ sudo mkdir -p /home/ftp/ftpuser1 /home/ftp/ftpuser2
$ sudo chown ftp:nogroup /home/ftp/ftpuser1 /home/ftp/ftpuser2
# 語法:建立新ftp使用者,並儲存到proftpd.passwd
# sudo ftpasswd --passwd --name=$virtual_user --gid=$real_user_gid --uid=$real_user_uid --home=$virtual_user_home --shell=/bin/false --file=/output_file/proftpd.passwd
$ sudo ftpasswd --passwd --name=ftpuser1 --uid=118 --gid=65534 --shell=/bin/false --home=/home/ftp/ftpuser1 --file=/etc/proftpd.passwd
$ sudo ftpasswd --passwd --name=ftpuser1 --uid=118 --gid=65534 --shell=/bin/false --home=/home/ftp/ftpuser2 --file=/etc/proftpd.passwd
# 語法:建立新ftp群組,並儲存到proftpd.group
# sudo ftpasswd --group --name=$virtual_group --gid=$real_user_gid --member=virtual_user --file=/output_file/proftpd.group
# 如果你跟我一樣想使用系統原group就好,則忽略以下這一行!
$ sudo ftpasswd --group --name=nogroup --gid=65534 --member=ftpuser1 --member=ftpuser2 -file=/etc/proftpd.group
- 接著就來設定/etc/proftpd/proftpd.conf,確認以下的設定:
# 由xinetd管理
ServerType inetd
DefaultServer on
# 使用自製的passwd檔
AuthUserFile /etc/proftpd.passwd
# 使用自製的group檔
# AuthGroupFile /etc/proftpd.group
# 只使用自製的passwd及group檔
AuthOrder mod_auth_file.c
# 不需要有效的shell也能登入FTP,方便Virtual user登入
RequireValidShell off
Port 1226
- 到/etc/xinetd.d建立proftpd起始設定:
$ sudo vim /etc/xinetd.d/proftpd
# 鍵入以下設定
service ftp
{
disable = no
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/proftpd
server_args = -c /etc/proftpd/proftpd.conf
log_on_success += DURATION USERID
log_on_failure += USERID
}
- 再進入/etc/services,註解掉原service port設定,在最後一行輸入設定新port:
$ sudo vim /etc/services
...........
#ftp 21/tcp
...........
...........
# Local services
ftp 1226/tcp # ProFTPD (ftp daemon),不要用其他service name!
- 重新啟動xinetd吧~這樣proftpd就會被跟著啟動了:
$ sudo /etc/initd.d/xinetd restart
$ sudo netstat -tlnp | grep 1226
tcp 0 0 0.0.0.0:1226 0.0.0.0:* LISTEN 1171/xinetd
- 一定要設定好防火牆,你可以用Firstarter圖形介面設定其實蠻容易的,如果沒有Firestarter再用iptable的指令:
$ iptable -A INPUT -s 192.168.1.0/24 -p tcp --dport 1226 -j ACCEP
- 安裝xinetd及ProFTPD:
- 參考資料:
- 鳥哥的Linux私房菜
xinetd(super deamon):http://linux.vbird.org/linux_basic/0560daemons.php
ProFTPD:http://linux.vbird.org/linux_server/0410proftpd.php
iptables:http://linux.vbird.org/linux_server/0250simple_firewall.php#netfilter - ProFTPD 虛擬帳號@ 創造心理的感動:http://gisanfu.pixnet.net/blog/post/6501095-proftpd-%E8%99%9B%E6%93%AC%E5%B8%B3%E8%99%9F
- proftpd 如何建立獨立帳號:/moto.debian.tw/viewtopic.php?p=35579
- 鳥哥的Linux私房菜
- 延伸資料:
- 鳥哥的Linux私房菜
Virtual Host:http://linux.vbird.org/linux_server/0360apache.php#www_adv_virtual
- 鳥哥的Linux私房菜
全站熱搜