Centos6.5部署ftp文件服务器

1.检查vsftpd是否安装

root@centos ~]# rpm -qa|grep vsftpd

vsftpd-2.2.2-14.el6.x86_64

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

[root@centos ~]# yum install vsftpd -y

2.配置防火墙

vsftpd软件安装完后,默认端口是21,所以需要在防火墙配置中开放21端口

[root@centos ~]# vim /etc/sysconfig/iptables

# Firewall configuration written by system-config-firewall

# Manual customization of this file is not recommended.

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT

防火墙配置完后,需要重启防火墙服务,配置才会生效

[root@centos ~]# service iptables restart

3.启动vsftpd前的一些必要配置

3.1 关闭selinux,将enforcing改为disabled

[root@centos ~]# cat /etc/selinux/config |grep ^[^#]

ELINUX=disabled

SELINUXTYPE=targeted

3.2 setsebool设置

[root@centos ~]# setsebool ftpd_disable_trans 1

[root@centos ~]# setsebool -P ftp_home_dir=1

4.启动vsftpd服务,并设置为开机自启动

[root@centos ~]# service vsftpd start

Starting vsftpd for vsftpd:                                [  OK  ]

[root@centos ~]# chkconfig vsftpd on

[root@centos ~]# netstat -lnput |grep vsftpd

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用户的命令如下:

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

此命令的含义:

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

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

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

 

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

[root@centos ~]# cat /etc/vsftpd/vsftpd.conf |grep ^[^#]

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

xferlog_std_format=YES

idle_session_timeout=600

chroot_local_user=YES

listen=YES

pam_service_name=vsftpd

userlist_enable=YES

tcp_wrappers=YES

listen_port=2510

 

8.限制客户端的可连接IP地址

首先检查vsftpd.conf中的tcp_wrappers

[root@centos vsftpd]# grep "tcp_wrappers" /etc/vsftpd/vsftpd.conf

tcp_wrappers=YES


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

[root@centos vsftpd]# vim /etc/hosts.deny

#

# hosts.deny    This file contains access rules which are used to

#               deny connections to network services that either use

#               the tcp_wrappers library or that have been

#               started through a tcp_wrappers-enabled xinetd.

#

#               The rules in this file can also be set up in

#               /etc/hosts.allow with a 'deny' option instead.

#

#               See 'man 5 hosts_options' and 'man 5 hosts_access'

#               for information on rule syntax.

#               See 'man tcpd' for information on tcp_wrappers

#

vsftpd:all:Deny   //限制所有网段都不可以连接

接下来编辑hosts.allow文件,允许192.168.1网段可以连接

[root@centos vsftpd]# vim /etc/hosts.allow

#

# hosts.allow   This file contains access rules which are used to

#               allow or deny connections to network services that

#               either use the tcp_wrappers library or that have been

#               started through a tcp_wrappers-enabled xinetd.

#

#               See 'man 5 hosts_options' and 'man 5 hosts_access'

#               for information on rule syntax.

#               See 'man tcpd' for information on tcp_wrappers

#

vsftpd:192.168.1.*:Allow  //开放192.168.1网络可以连接

9.使用chattr命令可以对某个文件夹下的内容只允许上传和下载,而不许删除

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

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

[root@centos /]# chmod -R 500 /ftp/Upload

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29812844/viewspace-2122316/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29812844/viewspace-2122316/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值