在linux服務器上搭建相對安全的FTP服務器

一、如何在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文件夾已經存在,但要確認已存在的文件夾是否僅是個鏈接

  1. mkdir -p /etc/ssl/certs  
  2. chmod 700 /etc/ssl/certs  
3、執行生成證書的命令:

  1. openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout /etc/ssl/certs/vsftpd.pem -out /etc/ssl/certs/vsftpd.pem  
4、上述證書生成過程中需要填寫信息,按提示添加國家、省份、郵箱等即可,可以隨便填,信息後續用不到;

5、然後進到/etc/ssl/certs目錄下看證書有沒有生成

6、然後我們修改vsftpd的配置文件在最後添加如下信息

  1. # Turn on SSL  
  2. ssl_enable=YES  
  3.    
  4. # Allow anonymous users to use secured SSL connections  
  5. allow_anon_ssl=YES  
  6.    
  7. # All non-anonymous logins are forced to use a secure SSL connection in order to  
  8. # send and receive data on data connections.  
  9. force_local_data_ssl=YES  
  10. force_anon_data_ssl=YES  
  11.    
  12. # All non-anonymous logins are forced to use a secure SSL connection in order to send the password.  
  13. force_local_logins_ssl=YES  
  14. force_anon_logins_ssl=YES  
  15.    
  16. # Permit TLS v1 protocol connections. TLS v1 connections are preferred  
  17. ssl_tlsv1=YES  
  18.    
  19. # Permit SSL v2 protocol connections. TLS v1 connections are preferred  
  20. ssl_sslv2=NO  
  21.    
  22. # permit SSL v3 protocol connections. TLS v1 connections are preferred  
  23. ssl_sslv3=NO  
  24.    
  25. # Disable SSL session reuse (required by WinSCP)  
  26. require_ssl_reuse=NO  
  27.    
  28. # Select which SSL ciphers vsftpd will allow for encrypted SSL connections (required by FileZilla)  
  29. ssl_ciphers=HIGH  
  30.    
  31. # This option specifies the location of the RSA certificate to use for SSL  
  32. # encrypted connections.  
  33. rsa_cert_file=/etc/ssl/cert/vsftpd.pem  
7、配置修改完成後,重新vsftpd服務。

備註:如服務啓動失敗,請確認證書存儲的位置與下面填寫的是否符合   sa_cert_file=/etc/ssl/cert/vsftpd.pem 

8、登陸查看是否已加密

狀態: 正在連接 172.20.100.XX:21...
狀態: 連接建立,等待歡迎消息...
狀態: 初始化 TLS 中...
狀態: 正在驗證證書...
狀態: TLS 連接已建立。
狀態: 已登錄
狀態: 讀取目錄列表...


備註:需要使用工具鏈接,如FileZilla等,直接通過瀏覽器可能無法正常登陸。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章