Centos6.5部署ftp文件服務器

原文地址:http://blog.csdn.net/u011364306/article/details/48490143


1.檢查vsftpd是否安裝

  1. root@centos ~]# rpm -qa|grep vsftpd  
  2. vsftpd-2.2.2-14.el6.x86_64  

1.1如未安裝,進行yum安裝vsftpd

  1. [root@centos ~]# yum install vsftpd -y  
2.配置防火牆 
vsftpd軟件安裝完後,默認端口是21,所以需要在防火牆配置中開放21端口

  1. [root@centos ~]# vim /etc/sysconfig/iptables  
  2. # Firewall configuration written by system-config-firewall  
  3. # Manual customization of this file is not recommended.  
  4. *filter  
  5. :INPUT ACCEPT [0:0]  
  6. :FORWARD ACCEPT [0:0]  
  7. :OUTPUT ACCEPT [0:0]  
  8. -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT  
  9. -A INPUT -p icmp -j ACCEPT  
  10. -A INPUT -i lo -j ACCEPT  
  11. -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT  
  12. -A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT  
  13. -A INPUT -j REJECT --reject-with icmp-host-prohibited  
  14. -A FORWARD -j REJECT --reject-with icmp-host-prohibited  
  15. COMMIT  
防火牆配置完後,需要重啓防火牆服務,配置纔會生效
  1. [root@centos ~]# service iptables restart  
3.啓動vsftpd前的一些必要配置
3.1關閉selinux,將enforcing改爲disabled

  1. [root@centos ~]# cat /etc/selinux/config |grep ^[^#]  
  2. ELINUX=disabled  
  3. SELINUXTYPE=targeted  
3.2setsebool設置

  1. [root@centos ~]# setsebool ftpd_disable_trans 1  
  2. [root@centos ~]# setsebool -P ftp_home_dir=1  
4.啓動vsftpd服務,並設置爲開機自啓動

  1. [root@centos ~]# service vsftpd start  
  2. Starting vsftpd for vsftpd:                                [  OK  ]  
  3.   
  4. [root@centos ~]# chkconfig vsftpd on  
  5.   
  6. [root@centos ~]# netstat -lnput |grep vsftpd  
  7. tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      1797/vsftpd  
5.與 vsftpd 服務器有關的文件和文件夾
vsftpd服務器的配置文件的是: /etc/vsftpd/vsftpd.conf
vsftpd服務器的根目錄,即FTP服務器的主目錄:/var/ftp/pub

6.添加FTP本地用戶(虛擬用戶)

FTP大家可能都用過,通過給定的HOST、賬號、密碼就可以訪問服務器對應的目錄空間了。但是,這個FTP賬號只能訪問FTP服務,不能登錄服務器系統,只能訪問自己的目錄。這樣的用戶就叫虛擬用戶,本質上這不叫虛擬用戶,僅僅只是不能通過終端等一系列途徑登錄服務器系統而已。

創建一個FTP用戶的命令如下:

  1. useradd -d /ftp -g ftp -s /sbin/nologin ftpserver  

此命令的含義:
使用shell命令useradd添加一個ftpserver的系統賬戶,但是不能登錄系統(-s /sbin/nologin),該賬戶的主目錄在(-d /ftp),屬於ftp這個用戶組(-g ftp)

我們創建了一個FTP賬戶,現在來設置賬戶的密碼,命令如下

  1. passwd ftpserver  


7.vsftpd 配置文件的調整

anonymous_enable=NO   

//設定不允許匿名訪問,默認爲YES


local_enable=YES
//設定本地用戶可以訪問,默認爲YES。注:如使用虛擬宿主用戶,在該項目設定爲NO的情況下所有虛擬用戶將無法訪問。


chroot_local_user=YES

//使所有用戶不能離開主目錄,默認被#註釋,

注:如果要限制特定用戶不可以切換主目錄

將#chroot_list_enable=YES,#chroot_list_file=/etc/vsftpd/chroot_list前#註釋掉,並在/etc/vsftpd/chroot_list下添加制定的用戶即可


xferlog_file=/var/log/vsftpd.log
//設定vsftpd的服務日誌保存路徑,默認被#註釋。注意,該文件默認不存在。必須要手動touch


listen_port=2510

//默認端口爲21,爲了安全性可以修改該端口如上,修改好記得重啓服務和加入防火牆配置


idle_session_timeout=600

//默認爲600秒,空閒時間過久連接會中斷,默認未啓用,需將#號刪除


更詳細的參數解析:http://blog.csdn.net/u011364306/article/details/49078127


以下爲本機使用的參數文件配置

  1. [root@centos ~]# cat /etc/vsftpd/vsftpd.conf |grep ^[^#]  
  2. anonymous_enable=NO  
  3. local_enable=YES  
  4. write_enable=YES  
  5. local_umask=022  
  6. dirmessage_enable=YES  
  7. xferlog_enable=YES  
  8. connect_from_port_20=YES  
  9. xferlog_file=/var/log/xferlog  
  10. xferlog_std_format=YES  
  11. idle_session_timeout=600  
  12. chroot_local_user=YES  
  13. listen=YES  
  14. pam_service_name=vsftpd  
  15. userlist_enable=YES  
  16. tcp_wrappers=YES  
  17. listen_port=2510  

8.限制客戶端的可連接IP地址

首先檢查vsftpd.conf中的tcp_wrappers

  1. [root@centos vsftpd]# grep "tcp_wrappers" /etc/vsftpd/vsftpd.conf  
  2. tcp_wrappers=YES  

配置hosts.deny文件,限制所有網段不能連接

  1. [root@centos vsftpd]# vim /etc/hosts.deny  
  2. #  
  3. # hosts.deny    This file contains access rules which are used to  
  4. #               deny connections to network services that either use  
  5. #               the tcp_wrappers library or that have been  
  6. #               started through a tcp_wrappers-enabled xinetd.  
  7. #  
  8. #               The rules in this file can also be set up in  
  9. #               /etc/hosts.allow with a 'deny' option instead.  
  10. #  
  11. #               See 'man 5 hosts_options' and 'man 5 hosts_access'  
  12. #               for information on rule syntax.  
  13. #               See 'man tcpd' for information on tcp_wrappers  
  14. #  
  15. vsftpd:all:Deny   //限制所有網段都不可以連接  
接下來編輯hosts.allow文件,允許192.168.1網段可以連接

  1. [root@centos vsftpd]# vim /etc/hosts.allow  
  2. #  
  3. # hosts.allow   This file contains access rules which are used to  
  4. #               allow or deny connections to network services that  
  5. #               either use the tcp_wrappers library or that have been  
  6. #               started through a tcp_wrappers-enabled xinetd.  
  7. #  
  8. #               See 'man 5 hosts_options' and 'man 5 hosts_access'  
  9. #               for information on rule syntax.  
  10. #               See 'man tcpd' for information on tcp_wrappers  
  11. #  
  12. vsftpd:192.168.1.*:Allow  //開放192.168.1網絡可以連接  

9.使用chattr命令可以對某個文件夾下的內容只允許上傳和下載,而不許刪除

  1. [root@centos /]# chattr +a /ftp/Upload  

10.對目錄設置500權限就將該文件夾只許下載,不許上傳和刪除

  1. [root@centos /]# chmod -R 500 /ftp/Upload  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章