2016年9月7日 星期三

筆記:安裝Proftpd 和 OpenSSL(TSL功能)

這裡假設你已經有基本Linux操作能力,或是自行找尋操作資料的能力。
下例是以Linux lubuntu 4.4.0-21-generic  進行設定。
(版本查詢:
$ uname -a



一、安裝Proftpd 和 OpenSSL,及設定:


$ sudo apt-get install proftpd openssl

 Proftpd 的設定檔放在 /etc/proftpd/proftpd.conf之下,使用Vi進行編輯。
(安裝vi)

$ sudo apt-get install vi
 vi基本的操作:
  1. 鍵盤"i"鍵:啟動輸入;退出輸入請按下esc
  2. 鍵盤":"鍵:輸入其他指令
  3. 指令q:退出vi,如果有更動內容,又不想存檔,請輸入q!強制退出
  4. 指令w:寫入已更動的內容,wq即為存檔離開
  5. 鍵盤"/"鍵:啟動搜尋功能

其他操作請以vi 操作指令為關鍵字進行搜尋

(進入編輯proftpd.conf)
$ vi /etc/proftpd/proftpd.conf
DefaultRoot為關鍵字,找到後,更動內容如下:


[...]
DefaultRoot ~
IdentLookups off
ServerIdent on "FTP Server ready."
[...]

二、設定TLS在Proftpd上的設定檔

開啟Proftpd的設定檔:/etc/proftpd/proftpd.conf


$ sudo vi /etc/proftpd/proftpd.conf

找到內容中
" Include /etc/proftpd/tls.conf "這行,把前面的#號刪除,取消註解
[...]
#
# This is used for FTPS connections
#
Include /etc/proftpd/tls.conf
[...]
之後開啟 /etc/proftpd/tls.conf 這個文件,一樣以vi進行編輯

$ sudo vi /etc/proftpd/tls.conf
將內容取消註解,使其如下:

TLSEngine on
TLSLog /var/log/proftpd/tls.log
TLSProtocol SSLv23
TLSRSACertificateFile /etc/ssl/certs/proftpd.crt
TLSRSACertificateKeyFile /etc/ssl/private/proftpd.key

三、產生新的 SSL憑證 予TSL
原出處的範例是放在proftpd下自建的目錄:  /etc/proftpd/ssl/

$ mkdir /etc/proftpd/ssl
之後可以產生新的SSL憑證放置該目錄下,指令為:
$ sudo openssl req -x509 -newkey rsa:1024 -keyout /etc/ssl/private/proftpd.key -out /etc/ssl/certs/proftpd.crt -nodes -days 3650
(注意要接成一行)
之後會要求你輸入該憑證的資料:


Country Name (2 letter code) [AU]: ← 輸入你的國家名稱 ex:TW
State or Province Name (full name) [Some-State]: ←輸入你的洲郡省份
Locality Name (eg, city) []: ←輸入你的城市名
Organization Name (eg, company) [Internet Widgits Pty Ltd]: ←輸入你的組織名稱,比如學校、公司行號
Organizational Unit Name (eg, section) []: ←輸入你的組識單位,例如 資工系、資訊部 (e.g. "IT Department").
Common Name (eg, YOUR name) []: ←輸入你的完整 合法網路位址或是伺服器系統名稱(e.g. "server1.example.com").
Email Address []: ←輸入你的E-mail位址

之後實際登入大略會是這樣(以Filzilla為例):


四、設定FTP專用帳號 

Proftpd的使用者是使用Linux系統的使用者資料庫(/etc/passwd 和 /etc/shadow)
在這裡會設定一個僅用於FTP登入,但無法用於Lubunt登入的帳號"ftper"。
useradd --shell /bin/false tom
使用 /bin/false這個shell,可以禁止該帳號使用系統登入,除了外部服務。(ex:該系統上的電子郵件、ftp服務等)
產生 ftper 的家目錄,並將該目錄的擁有者設為 ftper

$ sudo mkdir /home/ftper
$ sudo chown ftper:ftper /home/ftper/ 

如果需要不同名稱, 或是其他位置的家目錄,指令如下

$sudo useradd --home /srv/ftponly --create-home --shell /bin/false tom

這裡的設定是將預設的家目錄設定為 /srv/ftponly 並建立帳號

最後則是設定帳號密碼

$sudo passwd ftper
系統會要求輸入想要的密碼
註:如果發生帳號無法登入的問題,請把 /bin/false 加到 /etc/shells 裡面

參考網站:
How to install ProFTPd with TLS support on Ubuntu 16.04


[Linux] 架設 Proftp 與 FTP over TLS 供網頁工讀生上傳資料 @ Ubuntu 12.04

在 Ubuntu 建立 FTP 帳號,shell 使用 /bin/false 或 /sbin/nologin 均無法登入