centos7 搭建ftp 并配置用户目录

1.如果是阿里云服务器,登录控制后台,配置规则,开启21端口 (sftp是加密文件传输使用的22端口,我们这几是搭建ftp服务器)

2.安装配置vsftp服务器

一、配置防火墙,开启FTP服务器需要的端口

CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。

1、关闭firewall:

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall开机启动

         

2、安装iptables防火墙

yum install iptables-services #安装

vi /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 -m state --state NEW -m tcp -p tcp --dport 10060:10090 -j ACCEPT

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

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

COMMIT

:wq! #保存退出

systemctl restart iptables.service #最后重启防火墙使配置生效

systemctl enable iptables.service #设置防火墙开机启动

说明:21端口是ftp服务端口;10060到10090是Vsftpd被动模式需要的端口,可自定义一段大于1024的tcp端口。

系统运维  www.osyunwei.com  温馨提醒:qihang01原创内容©版权所有,转载请注明出处及原文链接

二、关闭SELINUX

vi /etc/selinux/config

#SELINUX=enforcing #注释掉

#SELINUXTYPE=targeted #注释掉

SELINUX=disabled #增加

:wq! #保存退出

setenforce 0 #使配置立即生效

三、安装vsftpd

yum install -y vsftpd #安装vsftpd

yum install -y psmisc net-tools systemd-devel libdb-devel perl-DBI  #安装vsftpd虚拟用户配置依赖包

systemctl start vsftpd.service #启动

systemctl enable vsftpd.service #设置vsftpd开机启动

四、配置vsftp服务器

cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf-bak #备份默认配置文件

五、新建用户并制定目录

useradd -d /home/test -s /sbin/nologin test

chown -R test:test /home/test 为目录指定用户

chomd -R 755 /home/test  给用户赋予权限 注意一定是755,

六、如果想要用户登录后不能访问上级目录

修改/etc/vsftpd/vsftpd.conf如下:

chroot_list_enable=YES //限制访问自身目录
# (default follows)
chroot_list_file=/etc/vsftpd/vsftpd.chroot_list

将用户名及密码 换行写在 vsftpd.chroot_list中

然后重启vsftpd 服务

systemctl restart vsftpd.service

systemctl enable vsftpd.service 开机启动服务

posted @ 2018-03-30 13:59  fibst  阅读(1844)  评论(0编辑  收藏  举报