Centos6.5部署ftp文件服务器

来源:互联网 发布:手机千牛淘宝客插件 编辑:程序博客网 时间:2024/05/22 11:40

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


1.检查vsftpd是否安装

[plain] view plaincopyprint?
  1. root@centos ~]# rpm -qa|grep vsftpd  
  2. vsftpd-2.2.2-14.el6.x86_64  

1.1如未安装,进行yum安装vsftpd

[plain] view plaincopyprint?
  1. [root@centos ~]# yum install vsftpd -y  
2.配置防火墙 
vsftpd软件安装完后,默认端口是21,所以需要在防火墙配置中开放21端口

[plain] view plaincopyprint?
  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  
防火墙配置完后,需要重启防火墙服务,配置才会生效
[plain] view plaincopyprint?
  1. [root@centos ~]# service iptables restart  
3.启动vsftpd前的一些必要配置
3.1关闭selinux,将enforcing改为disabled

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

[plain] view plaincopyprint?
  1. [root@centos ~]# setsebool ftpd_disable_trans 1  
  2. [root@centos ~]# setsebool -P ftp_home_dir=1  
4.启动vsftpd服务,并设置为开机自启动

[plain] view plaincopyprint?
  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用户的命令如下:

[plain] view plaincopyprint?
  1. useradd -d /ftp -g ftp -s /sbin/nologin ftpserver  

此命令的含义:
使用shell命令useradd添加一个ftpserver的系统账户,但是不能登录系统(-s /sbin/nologin),该账户的主目录在(-d /ftp),属于ftp这个用户组(-g ftp)

我们创建了一个FTP账户,现在来设置账户的密码,命令如下

[plain] view plaincopyprint?
  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


以下为本机使用的参数文件配置

[plain] view plaincopyprint?
  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

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

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

[plain] view plaincopyprint?
  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网段可以连接

[plain] view plaincopyprint?
  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命令可以对某个文件夹下的内容只允许上传和下载,而不许删除

[plain] view plaincopyprint?
  1. [root@centos /]# chattr +a /ftp/Upload  

10.对目录设置500权限就将该文件夹只许下载,不许上传和删除

[plain] view plaincopyprint?
  1. [root@centos /]# chmod -R 500 /ftp/Upload  
0 0
原创粉丝点击