在 CentOS 7.x 下安裝 Proftpd Server

參考網站:
Linux . 無限: 在 CentOS7/RHEL7 上架設 Proftpd Server

1. 安裝 EPEL 套件庫
# yum install epel-release
# yum update

2. 安裝 Proftpd Server 相關套件
# yum install proftpd proftpd-ldap proftpd-mysql proftpd-utils

3. 防火牆設定
# firewall-cmd –permanent –add-service=ftp
# firewall-cmd –reload

# iptables -A INPUT -p tcp –syn -m state –state NEW –dport 21 -j ACCEPT
[@more@]
4.
# cp /etc/proftpd.conf /etc/proftpd.conf.$(date +%F)

# yum install openssl

# openssl req -x509 -newkey rsa:1024 -keyout /etc/proftpd.d/proftpd.key -out /etc/proftpd.d/proftpd.crt -nodes -days 3650
Generating a 1024 bit RSA private key
……….++++++
……++++++
writing new private key to ‘/etc/proftpd.d/proftpd.key’
—–
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [TW]:
State or Province Name (full name) [Yilan]:
Locality Name (eg, city) [TouCheng]:
Organization Name (eg, company) [Elementary School]:
Organizational Unit Name (eg, section) [Proxy Server]:FTP Server
Common Name (eg, your name or your server’s hostname) []:
Email Address []:

4. 啟動 Proftpd Serve,並設定開機時啟動
# systemctl start proftpd.service
# systemctl enable proftpd.service

vsftpd Over SSL/TLS 使用加密傳輸

FTP Server 在傳輸資料時都是使用明碼,沒有加密傳輸,使用 SSL/TLS 加密傳輸,可以使 FTP Server 在傳輸資料時更加安全。
參考網頁:
Vsftpd Over SSL/TLS使用加密傳輸:::iThome Download-你要的軟體在這裡:::

1. 安裝 openssl / vsftpd 套件
# yum install openssl vsftpd

2. 建立憑證
# openssl req -x509 -nodes -days 3650 -newkey rsa:1024 -keyout /etc/pki/tls/certs/vsftpd.pem -out /etc/pki/tls/certs/vsftpd.pem
Generating a 1024 bit RSA private key
..++++++
…..++++++
writing new private key to ‘/etc/pki/tls/certs/vsftpd.pem’
—–
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [TW]:
State or Province Name (full name) [Yilan]:
Locality Name (eg, city) [TouCheng]:
Organization Name (eg, company) [Elementary School]:
Organizational Unit Name (eg, section) [Proxy Server]:FTP Server
Common Name (eg, your name or your server’s hostname) []:xxx.tces.ilc.edu.tw
Email Address []:xxx@gmail.com

[@more@]3. 更改檔案權限
# chmod 600 /etc/pki/tls/certs/vsftpd.pem

4. 修改 vsftp FTP Server 設定檔 /etc/vsftpd/vsftpd.conf
# cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.$(date +%F)
# vim /etc/vsftpd/vsftpd.conf
在設定檔的最後面加上
# 憑證存放路徑
rsa_cert_file=/etc/pki/tls/certs/vsftpd.pem
# 啟動 SSL
ssl_enable=YES
# 強制傳輸時使用 SSL
force_local_data_ssl=YES
# 登入時強制使用 SSL
force_local_logins_ssl=YES

可以使用的參數
ssl_enable=yes/no //是否啟用 SSL,預設為 no
allow_anon_ssl=yes/no //是否允許匿名使用者使用 SSL,預設為 no
rsa_cert_file=/path/to/file //rsa 證書的位置
dsa_cert_file=/path/to/file //dsa 證書的位置
force_local_logins_ssl=yes/no //非匿名使用者登陸時是否加密,預設為 yes
force_local_data_ssl=yes/no //非匿名使用者傳輸資料時是否加密,預設為 yes
force_anon_logins_ssl=yes/no //匿名使用者登錄時是否加密,預設為 no
force_anon_data_ssl=yes/no //匿名使用者資料傳輸時是否加密,預設為 no
ssl_sslv2=yes/no //是否啟動 ssl v2 加密,預設 no
ssl_sslv3=yes/no //是否啟動 ssl v3 加密,預設 no
ssl_tlsv1=yes/no //是否啟動 tls v1 加密,預設 yes
ssl_ciphers=HIGH //預設是 DES-CBC3-SHA

5. 重新啟動 vsftpd FTP Server
# systemctl restart vsftpd.service

6. 使用 FileZilla 進行測試

解決在 CentOS 7.x vsftpd FTP Server 出現 500 OOPS 的錯誤訊息

一般使用者連線時出現 500 OOPS 的錯誤訊息
# lftp -u t850008 127.0.0.1
Password:
lftp t850008@127.0.0.1:~> ls
ls: Login failed: 500 OOPS: vsftpd: refusing to run with writable root inside chroot()[@more@]解決方式:
1. 修改 /etc/vsftpd/vsftpd.conf 設定檔
# vim /etc/vsftpd/vsftpd.conf
加入下面一行
allow_writeable_chroot=YES

2. 重新啟動 vsftpd FTP Server
# systemctl stop vsftpd
# systemctl start vsftpd

3. 測試一下
# lftp -u t850008 127.0.0.1
Password:
lftp t850008@127.0.0.1:~> ls
-rw——-    1 1000     1000     73121952 Jun 26 00:51 VMware-player-12.1.0-3272444.exe
-rw——-    1 1000     1000     153807839 Jun 26 00:52 Windows 7 Games for Windows 10 and 8.exe
-rw——-    1 1000     1000       324096 Jun 26 00:51 pietty0327.exe

在 CentOS 7.x 上使用 vsftpd FTP Server

1. 安裝 vsftpd FTP Server
# yum install -y vsftpd

2. 修改設定檔 /etc/vsftpd/vsftpd.conf
# grep -v ^# /etc/vsftpd/vsftpd.conf
anonymous_enable=No
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_file=/var/log/xferlog
idle_session_timeout=600
data_connection_timeout=120
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
allow_writeable_chroot=YES
listen=YES

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

pasv_enable=YES
pasv_min_port=5000
pasv_max_port=6000
use_localtime=YES[@more@]3. 讓 root 可以登入
# sed -i ‘s/root/#root/’ /etc/vsftpd/ftpusers
# sed -i ‘s/root/#root/’ /etc/vsftpd/user_list

4. 限制使用者不能切換到其它目錄,root 可以
# echo root > /etc/vsftpd/chroot_list

5. SELinux 在 vsftpd FTP Server 上的設定
# setsebool -P ftp_home_dir  on
# setsebool -P allow_ftpd_full_access  on

6. 設定開機時啟動
# # systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

7. 啟動 vsftpd FTP Server
# systemctl start vsftpd

8. 檢查 FTP Server 是否有正常啟動
# netstat -ant | grep :21
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN

關於 chroot 使用者的另一種做法
1. 修改 /etc/vsftpd/vsftpd.conf 設定檔
# grep ‘chroot’ /etc/vsftpd/vsftpd.conf | grep -v ‘^#’
chroot_local_user=NO
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
allow_writeable_chroot=YES

2. 建立要 chroot 的使用者
# awk -F: ‘{if ($3>999) print $1}’ /etc/passwd | grep -v nfsnobody > /etc/vsftpd/chroot_list

# awk -F: ‘{if ($3>999&&$3<60000) print $1}’ /etc/passwd > /etc/vsftpd/chroot_list

在 CentOS 6.x 上使用 vsftpd FTP Server

1. 安裝 vsftpd FTP Server
# yum install -y vsftpd

2. 修改設定檔 /etc/vsftpd/vsftpd.conf
# grep -v ^# /etc/vsftpd/vsftpd.conf
anonymous_enable=No
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
listen=YES
pasv_enable=YES
pasv_min_port=5000
pasv_max_port=6000
use_localtime=YES

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES[@more@]3. 讓 root 可以登入
# sed -i ‘s/root/#root/’ /etc/vsftpd/ftpusers
# sed -i ‘s/root/#root/’ /etc/vsftpd/user_list

4. 限制使用者不能切換到其它目錄,root 可以
# echo root > /etc/vsftpd/chroot_list

5. SELinux 在 vsftpd FTP Server 上的設定
# setsebool -P ftp_home_dir  on
# setsebool -P allow_ftpd_full_access  on

6. 設定開機時啟動
# chkconfig –level 3 vsftpd on

7. 啟動 vsftpd FTP Server
# service vsftpd start

8. 檢查 FTP Server 是否有正常啟動
# netstat -ant | grep :21
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN

9. 防火牆設定
# iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 5000:6000 -j ACCEPT

在 Debian Linux 安裝 ProFTPD FTP Server

1. 搜尋套件
# apt-cache search proftpd | grep ^proftpd
proftpd-basic – Versatile, virtual-hosting FTP daemon – binaries
proftpd-dev – Versatile, virtual-hosting FTP daemon – development files
proftpd-doc – Versatile, virtual-hosting FTP daemon – documentation
proftpd-mod-geoip – Versatile, virtual-hosting FTP daemon – GeoIP module
proftpd-mod-ldap – Versatile, virtual-hosting FTP daemon – LDAP module
proftpd-mod-mysql – Versatile, virtual-hosting FTP daemon – MySQL module
proftpd-mod-odbc – Versatile, virtual-hosting FTP daemon – ODBC module
proftpd-mod-pgsql – Versatile, virtual-hosting FTP daemon – PostgreSQL module
proftpd-mod-sqlite – Versatile, virtual-hosting FTP daemon – SQLite3 module
proftpd-mod-autohost – ProFTPD module mod_autohost
proftpd-mod-case – ProFTPD module mod_case
proftpd-mod-dnsbl – ProFTPD module mod_dnsbl
proftpd-mod-fsync – ProFTPD module mod_fsync
proftpd-mod-msg – ProFTPD module mod_msg
proftpd-mod-tar – ProFTPD module mod_tar

2. 進行安裝
# apt-get install proftpd
standalone 方式啟動,效能會比較好
[@more@]3. 修改設定檔 /etc/proftpd/proftpd.conf
# grep -E -v ‘^#|^$’ /etc/proftpd/proftpd.conf
Include /etc/proftpd/modules.conf
UseIPv6                         on
IdentLookups                    off
ServerName                      “Debian”
ServerType                      standalone
DeferWelcome                    off
DefaultAddress                  192.168.1.12
MultilineRFC2228                on
DefaultServer                   on
ShowSymlinks                    on
TimeoutNoTransfer               600
TimeoutStalled                  600
TimeoutIdle                     1200
DisplayLogin                    welcome.msg
DisplayChdir                    .message true
ListOptions                     “-l”
DenyFilter                      *.*/
UseFtpUsers off
RootLogin on
DefaultRoot                     ~ !root
Port                            21
PassivePorts                  49152 65534
<IfModule mod_dynmasq.c>
</IfModule>
MaxInstances                    30
User                            proftpd
Group                           nogroup
Umask                           022  022
AllowOverwrite                  on
TransferLog /var/log/proftpd/xferlog
SystemLog   /var/log/proftpd/proftpd.log
<IfModule mod_quotatab.c>
QuotaEngine off
</IfModule>
<IfModule mod_ratio.c>
Ratios off
</IfModule>
<IfModule mod_delay.c>
DelayEngine on
</IfModule>
<IfModule mod_ctrls.c>
ControlsEngine        off
ControlsMaxClients    2
ControlsLog           /var/log/proftpd/controls.log
ControlsInterval      5
ControlsSocket        /var/run/proftpd/proftpd.sock
</IfModule>
<IfModule mod_ctrls_admin.c>
AdminControlsEngine off
</IfModule>
Include /etc/proftpd/conf.d/

4. 啟動 ProFTPD FTP Server
# /etc/init.d/proftpd start

5. 檢查 FTP Server 是否有正常啟動
# netstat -an | grep :21
tcp6       0      0 :::21                   :::*                    LISTEN

讓 ProFTPD Server root 可以登入

雖然是不太好的習慣,不過可以用 root 身份登入方便許多。
1. 修改 /usr/local/etc/proftpd.conf 設定檔
# vim /usr/local/etc/proftpd.conf
加入
# 讓 root 身份可以登入
RootLogin on
# 讓 root 可以自由切換到其它目錄
DefaultRoot ~ !wheel

2. 重新啟動 ProFTPD Server
# kill -HUP `ps aux | grep proftpd | grep -v grep | awk ‘{print $2}’`[@more@]3. 測試看看
# lftp -u root 127.0.0.1
密碼:
lftp root@127.0.0.1:~> ls
ls: 登入錯誤: 530 登入不正確
lftp root@127.0.0.1:~>

出現 530 登入不正確

4. 解決方式:
修改 /usr/local/etc/proftpd.conf 設定檔
# vim /usr/local/etc/proftpd.conf
加入
UseFtpUsers off

5. 再次重新啟動 ProFTPD Server
# kill -HUP `ps aux | grep proftpd | grep -v grep | awk ‘{print $2}’`

解決 ProFTPD Server 執行時出錯誤的訊息

在 FreeBSD 上執行時偶爾出現如下的錯誤訊息
# /usr/local/sbin/proftpd
2016-06-26 10:56:58,850 freebsd proftpd[730]: warning: unable to determine IP address of ‘freebsd’
2016-06-26 10:56:58,850 freebsd proftpd[730]: error: no valid servers configured
2016-06-26 10:56:58,850 freebsd proftpd[730]: fatal: error processing configuration file ‘/usr/local/etc/proftpd.conf’

看錯誤訊息似乎和 IP 有關,因為目前是使用 DHCP Server 自動取得 IP[@more@]修改 /usr/local/etc/proftpd.conf 設定檔,加入下面一行
IP 請設定成 Server 目前使用的 IP
# vim /usr/local/etc/proftpd.conf
DefaultAddress                  192.168.1.13

重新啟動後就正常了!
# /usr/local/sbin/proftpd &

在 FreeBSD 上安裝 ProFTPD Server

在 FreeBSD 上安裝和 FreeNAS 及 NAS4Free 相同的 FTP Server。
1. 安裝 ProFTPD Server
# pkg install proftpd

2. 設定檔位置 /usr/local/etc/proftpd.conf
# grep -v -E ‘^#|^$’ /usr/local/etc/proftpd.conf
ServerName                      “ProFTPD Default Installation”
ServerType                      standalone
DefaultServer                   on
ScoreboardFile          /var/run/proftpd/proftpd.scoreboard
Port                            21
UseIPv6                         on
Umask                           022
MaxInstances                    30
CommandBufferSize       512
User                            nobody
Group                           nogroup
DefaultRoot ~ !
AllowOverwrite          on
<Limit SITE_CHMOD>
  DenyAll
</Limit>
  ### We want clients to be able to login with “anonymous” as well as “ftp”
  # UserAlias                   anonymous ftp
  ### Limit the maximum number of anonymous logins
  # MaxClients                  10
  ### We want ‘welcome.msg’ displayed at login, and ‘.message’ displayed
  ### in each newly chdired directory.
  # DisplayLogin                        welcome.msg
  # DisplayFirstChdir           .message
  ### Limit WRITE everywhere in the anonymous chroot
  # <Limit WRITE>
  #   DenyAll
  # </Limit>[@more@]3. 修改 /etc/rc.conf,設定開機時啟動
# vim /etc/rc.conf
加入下面一行
proftpd_enable=”YES”

# echo ‘proftpd_enable=”YES”‘ >> /etc/rc.conf

4. 啟動 ProFTPD Server
# /usr/local/sbin/proftpd &

5. 檢查 FTP Server 是否有正常啟動
# netstat -an | grep *.21
tcp46      0      0 *.21                   *.*                    LISTEN

解決 FTP 時 550 Failed to change directory. 的問題

在建立 PXE Server 時,有透過 FTP 的方式來網路安裝 Linux,是使用 ln -s(Symbolic Link) 的方式來連結。
# ln -s /var/www/html/CentOS /var/ftp/CentOS

但建立完之後,使用 ftp 連線時,卻發現無法切換到 CentOS 目錄,出現 550 Failed to change directory 的錯誤訊息
# lftp 192.168.1.6
lftp 192.168.1.6:~> ls
lrwxrwxrwx    1 0        0              20 Jan 08 09:31 CentOS -> /var/www/html/CentOS
drwxr-xr-x    2 0        0            4096 Jan 08 09:29 Linux
drwxr-xr-x    2 0        0            4096 Jan 06 19:16 pub
lftp 192.168.1.6:/> cd CentOS/
cd: Access failed: 550 Failed to change directory. (/CentOS)
lftp 192.168.1.6:/> bye
[@more@]本來以為是 SELinux 的問題,幾乎把所有有關 ftp 的選項都打開了,也是沒有辦法
# getsebool -a | grep ftp
allow_ftpd_anon_write –> off
allow_ftpd_full_access –> on
allow_ftpd_use_cifs –> off
allow_ftpd_use_nfs –> off
ftp_home_dir –> on
ftpd_connect_db –> off
ftpd_use_fusefs –> off
ftpd_use_passive_mode –> on
httpd_enable_ftp_server –> off
tftp_anon_write –> off
tftp_use_cifs –> off
tftp_use_nfs –> off

後來乾脆來 SELinux 整個關掉,也是不行

後來在網路上找了很久,終於找到這一篇文章 網路一族: vsftp 出現 550 failed to change directory
文章中提到的第 2 點,可能是 Soft Link 的問題,因為 chroot 不能使用 Link 的功能

根據這一個提示,在網路上搜尋 Soft Link 550,在 FileZilla Forums • View topic – Symbolic links cause error 550 because path is too deep  找到了解決的方式

刪除原來的 Link
# rm -rf /var/ftp/CentOS
建立要連結的目錄
# mkdir /var/ftp/CentOS
使用 mount –bind 的方式來建立連結
 # mount –bind /var/www/html/CentOS /var/ftp/CentOS

這樣子就可以正常切換到 /var/ftp/CentOS 目錄了!