一、如何在Linux服務器上安裝vsftp不在多說,直接介紹如何進行安全性配置;
二、編輯vsftp.conf文件
關鍵配置項如下:
anonymous_enable=NO /禁止匿名用戶登錄
local_enable=YES /允許本地用戶登錄
write_enable=YES /允許登陸後寫
local_umask=022
xferlog_enable=YES /記錄日誌
xferlog_file=/var/log/xfer log /日誌文件
userlist_enable=YES /限制userlist裏面的本地用戶不能訪問,userlist裏面可以把root等禁止ftp登錄的本地賬號寫進去
所有配置項的註釋可參考:
http://blog.csdn.net/chenhongqian/article/details/50462382
三、創建FTP賬號
# useradd –d /home/myftp myftp
# passwd myftp
# usermod -s /sbin/nologin myftp //限定用戶myftp不能本地登錄
四、創建一個文件夾(scripts)只能下載,不能上傳
# mkdir scripts /home/myftp
#chmod 555 scripts
五、創建一個文件夾(results)只能上傳,不能下載和刪除
這個有點難度,因爲用戶不能對自己上傳的文件進行下載和刪除,需要使用特殊的方法。
# mkdir results /home/myftp
#chmod 755 results
#chattr +i /home/results
六、配置SSL加密
1、通過rpm -qa | openssl 查看是否已安裝openssl,未安裝請先安裝
2、新建目錄,爲了放置證書,有可能certs文件夾已經存在,但要確認已存在的文件夾是否僅是個鏈接。
- mkdir -p /etc/ssl/certs
- chmod 700 /etc/ssl/certs
- openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout /etc/ssl/certs/vsftpd.pem -out /etc/ssl/certs/vsftpd.pem
5、然後進到/etc/ssl/certs目錄下看證書有沒有生成
6、然後我們修改vsftpd的配置文件在最後添加如下信息
- # Turn on SSL
- ssl_enable=YES
- # Allow anonymous users to use secured SSL connections
- allow_anon_ssl=YES
- # All non-anonymous logins are forced to use a secure SSL connection in order to
- # send and receive data on data connections.
- force_local_data_ssl=YES
- force_anon_data_ssl=YES
- # All non-anonymous logins are forced to use a secure SSL connection in order to send the password.
- force_local_logins_ssl=YES
- force_anon_logins_ssl=YES
- # Permit TLS v1 protocol connections. TLS v1 connections are preferred
- ssl_tlsv1=YES
- # Permit SSL v2 protocol connections. TLS v1 connections are preferred
- ssl_sslv2=NO
- # permit SSL v3 protocol connections. TLS v1 connections are preferred
- ssl_sslv3=NO
- # Disable SSL session reuse (required by WinSCP)
- require_ssl_reuse=NO
- # Select which SSL ciphers vsftpd will allow for encrypted SSL connections (required by FileZilla)
- ssl_ciphers=HIGH
- # This option specifies the location of the RSA certificate to use for SSL
- # encrypted connections.
- rsa_cert_file=/etc/ssl/cert/vsftpd.pem
備註:如服務啓動失敗,請確認證書存儲的位置與下面填寫的是否符合 sa_cert_file=/etc/ssl/cert/vsftpd.pem
8、登陸查看是否已加密
狀態:
正在連接 172.20.100.XX:21...
狀態: 連接建立,等待歡迎消息...
狀態: 初始化 TLS 中...
狀態: 正在驗證證書...
狀態: TLS 連接已建立。
狀態: 已登錄
狀態: 讀取目錄列表...
備註:需要使用工具鏈接,如FileZilla等,直接通過瀏覽器可能無法正常登陸。