Friday, February 22, 2019

如何在Ubuntu 18.04.2建立一個anonymous FTP server?

FTP算是一個非常古老的檔案傳輸通訊協定,雖然現今已經不像以前那樣舉足輕重了,但是偶爾拿來使用一下還是挺方便的。

稍微紀錄一下如何在Ubuntu 18.04.2 Desktop建立一台anonymous FTP server。

安裝:
$ sudo apt update && apt install vsftpd

Ubuntu現在很好玩,當你安裝好任何一個service的時候,systemd就會自動把它enable與active,你可以透過以下的命令快速驗證一下:
$ systemctl status vsftpd
$ netstat -tupln | grep ftp















修改vsftpd.conf:
預設vsftpd並不允許anonymous去做檔案的上傳或下載,所以我們需要改變幾個參數讓它支援。
$ sudo vi /etc/vsftpd.conf
# Allow anonymous FTP? (Disabled by default).
anonymous_enable=YES

# Uncomment this to enable any form of FTP write command.
write_enable=YES

# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
anon_upload_enable=YES

改完之後記得重啟
$ sudo systemctl restart vsftpd

建立anonymous FTP folder:
Ubuntu預設的FTP server folder是在/srv/ftp,所以欲分享的檔案可以放在這邊。下圖你可以看到我share的檔案(左)可以被遠端的FTP client抓取(右)。











接下來建立一個folder pub under /srv/ftp來讓遠端user可以透過FTP上傳檔案。
$ cd /srv/ftp
$ sudo mkdir pub
$ sudo chmod 777 pub
$ sudo chown ftp.ftp pub















以上一個anonymous FTP server已經可以開始對外提供服務了,當然之後可以更進一步地研究如何架設一個regular user從自己的家目錄上傳或下載檔案。

補充:
如果你有開ufw(UncomplicatedFirewall)而且預設針對incoming traffic都是deny的話,記得加一下允許FTP連線的rule,例如:
$ sudo ufw allow from any to any port 20,21 proto tcp
(這邊暫時不考慮FTP PASV mode, 所以只需要開放TCP port 20,21) 

No comments: