Centos7 安装配置FTP服务
1、FTP简介
ftp(File Transfer Protocol文件传输协议)是基于TCP/IP 协议的应用层协议,用于文件的传输,包括ftp服务器(或服务端)和ftp客户端
FTP协议会在客户端和服务端创建两个连接,一个用于命令传输,一个用于数据传输。
主动模式和被动模式是面向服务端和数据传输来讲的。对于命令传输,都是客户端主动连接服务端。
主动模式:客户端创建一个listen端口,服务端主动连接,建立数据传输通道
被动模式:服务端创建一个listen端口,客户端主动链接,建立数据传输通道。
站在服务端的角度:
主动:客户端你来建立端口,我来连接。
被动:我建立好端口了,你来连接我。
2、关闭防火墙设置selinux
systemclt stop firewalld.service && systemclt disable firewalld.service
SELINUX=disabled
setenforce 0使修改立即生效
3、安装FTP
yum install vsftpd* -y
打印vsftpd安装后的配置文件路径
rpm –ql vsftpd | more
4、修改配置文件
vim /etc/vsftpd/vsftpd.conf
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
chroot_local_user=YES
chroot_list_enable=NO
allow_writeable_chroot=YES
chroot_list_file=/etc/vsftpd/chroot_list
listen=NO
listen_ipv6=YES
port_enable=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
pasv_min_port=64000
pasv_max_port=65000
local_root=/data/ftp/
# 是否开启匿名用户,匿名都不安全,默认NO
anonymous_enable=NO
# 允许本机账号登录FTP
# 这个设定值必须要为YES时,在/etc/passwd内的账号才能以实体用户的方式登入我们的vsftpd主机
local_enable=YES
# 允许账号都有写操作
write_enable=YES
# 本地用户创建文件或目录的掩码
# 意思是指:文件目录权限:777-022=755,文件权限:666-022=644
local_umask=022
# 进入某个目录的时候,是否在客户端提示一下
dirmessage_enable=YES
# 当设定为YES时,使用者上传与下载日志都会被记录起来
xferlog_enable=YES
# 日志成为std格式
xferlog_std_format=YES
# 上传与下载日志存放路径
xferlog_file=/var/log/xferlog
# 开放port模式的20端口的连接
connect_from_port_20=YES
# 关于系统安全的设定值:
# ascii_download_enable=YES(NO)
# 如果设定为YES,那么client就可以使用ASCII格式下载档案
# 一般来说,由于启动了这个设定项目可能会导致DoS的攻击,因此预设是NO
# ascii_upload_enable=YES(NO)
# 与上一个设定类似的,只是这个设定针对上传而言,预设是NO
ascii_upload_enable=NO
ascii_download_enable=NO
# 通过搭配能实现以下几种效果:
# ①当chroot_list_enable=YES,chroot_local_user=YES时,在/etc/vsftpd/chroot_list文件中列出的用户,可以切换到其他目录;未在文件中列出的用户,不能切换到其他目录
# ②当chroot_list_enable=YES,chroot_local_user=NO时,在/etc/vsftpd/chroot_list文件中列出的用户,不能切换到其他目录;未在文件中列出的用户,可以切换到其他目录
# ③当chroot_list_enable=NO,chroot_local_user=YES时,所有的用户均不能切换到其他目录
# ④当chroot_list_enable=NO,chroot_local_user=NO时,所有的用户均可以切换到其他目录
# 限制用户只能在自己的目录活动
chroot_local_user=YES
chroot_list_enable=NO
chroot_list_file=/etc/vsftpd/chroot_list
# 可以更改ftp的端口号,使用默认值21
# listen_port=60021
# 监听ipv4端口,开了这个就说明vsftpd可以独立运行,不用依赖其他服务
listen=NO
# 监听ipv6端口
listen_ipv6=YES
# 打开主动模式
port_enable=YES
# 启动被动式联机(passivemode)
pasv_enable=YES
# 被动模式端口范围:注意:linux客户端默认使用被动模式,windows 客户端默认使用主动模式。在ftp客户端中执行"passive"来切换数据通道的模式。也可以使用"ftp -A ip"直接使用主动模式。主动模式、被动模式是有客户端来指定的
# 上面两个是与passive mode使用的port number有关,如果您想要使用64000到65000这1000个port来进行被动式资料的连接,可以这样设定
# 这两项定义了可以同时执行下载链接的数量
# 被动模式起始端口,0为随机分配
pasv_min_port=64000
# 被动模式结束端口,0为随机分配
pasv_max_port=65000
# 文件末尾添加
# 这个是pam模块的名称,我们放置在/etc/pam.d/vsftpd,认证用
pam_service_name=vsftpd
# 使用允许登录的名单,在/etc/vsftpd/user_list文件中添加新建的用户ftpuser
userlist_enable=YES
# 限制允许登录的名单,前提是userlist_enable=YES,其实这里有点怪,禁止访问名单在/etc/vsftpd/ftpusers
userlist_deny=NO
# 允许限制在自己的目录活动的用户拥有写权限
# 不添加下面这个会报错:500 OOPS: vsftpd: refusing to run with writable root inside chroot()
allow_writeable_chroot=YES
# 当然我们都习惯支持TCP Wrappers的啦
# Tcp wrappers : Transmission Control Protocol (TCP) Wrappers 为由 inetd 生成的服务提供了增强的安全性
tcp_wrappers=YES
# FTP访问目录
local_root=/data/ftp/ftpuser
5、创建ftp用户和目录
useradd -d /data/ftp/ -s /sbin/nologin ftpuser
passwd ftpuser
mkdir -pv /data/ftp
chown -R ftpuser /data/ftp
6、启动ftp服务
systemctl enable vsftpd.service && systemctl start vsftpd.service && systemctl status vsftpd.service
7、报错修改
ftp 192.168.33.207
530 Login incorrect.
Login failed.
vim /etc/pam.d/vsftpd
注释这一行
auth required pam_shells.so
500 OOPS: vsftpd: refusing to run with writable root inside chroot()
Login failed.
421 Service not available, remote server has closed connection
vim /etc/vsftpd/vsftpd.conf
添加
allow_writeable_chroot=YES
8、登陆成功
9、配置防火墙策略
systemctl enable firewalld.service # 重启防火墙开机自启动
systemctl restart firewalld.service # 重启防火墙服务
firewall-cmd --version # 查看防火墙版本
firewall-cmd --list-all # 查看已开放的端口
firewall-cmd --permanent --zone=public --add-service=ftp # 防火墙开通ftp服务
firewall-cmd --permanent --zone=public --add-port=21/tcp # 开通ftp服务21命令控制端口
# 主动模式下数据传输端口等于命令控制端口-1 ======> 21 - 1 = 20
# 开通ftp服务主动模式的20数据传输端口
firewall-cmd --permanent --zone=public --add-port=20/tcp
# 开通ftp服务被动模式的数据端口范围
firewall-cmd --permanent --zone=public --add-port=64000-65000/tcp
firewall-cmd --reload # 刷新防火墙,重新载入
#————————————————————————————————firewall端口管理————————————————————————————————————————————————
#开放端口
firewall-cmd --zone=public --add-port=5672/tcp
#永久开放端口
firewall-cmd --zone=public --add-port=5672/tcp --permanent
#关闭端口
firewall-cmd --zone=public --remove-port=5672/tcp --permanent
# 配置立即生效
firewall-cmd --reload
#查看防火墙
firewall-cmd --list-all
#查看防火墙所有开放的端口
firewall-cmd --zone=public --list-ports
——————————————————————————————————————————————————————————————————————————————————————————————————
# 设置关闭SELinux对ftp的限制
setsebool -P ftpd_full_access on
sed -i s#enforcing#disabled#g /etc/sysconfig/selinux
setenforce 0 && getenforce
getenforce
10、修改FTP服务默认端口号
vim /etc/vsftpd/vsftpd.conf
添加
listen_port=8021
ftp_data_port=8020
vim /etc/services
找到ftp选项并将21修改成你设置的端口
重启服务
systemctl restart vsftpd.service
配置文件(修改无误)
vim /etc/vsftpd/vsftpd.conf
# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
# When SELinux is enforcing check for SE bool ftp_home_dir
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
xferlog_file=/var/log/xferlog
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode. The vsftpd.conf(5) man page explains
# the behaviour when these options are disabled.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enabl=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
chroot_local_user=YES
chroot_list_enable=NO
allow_writeable_chroot=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=NO
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
# Make sure, that one of the listen options is commented !!
listen_ipv6=YES
port_enable=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
pasv_min_port=50000
pasv_max_port=50002
#FTP访问目录
local_root=/data/ftp/
listen_port=8021
ftp_data_port=8020
Centos7 安装配置FTP服务的更多相关文章
- (转)Centos7安装配置NFS服务和挂载
Centos7安装配置NFS服务和挂载 原文:https://www.u22e.com/601.html NFS简介 NFS(Network File System)即网络文件系统,是FreeBSD支 ...
- CentOS系统下安装配置ftp服务
安装配置步骤: rpm -ivh /opt/bak/vsftpd-2.2.2-11.el6.x86_64.rpm --本地安装vsftpd ll /etc/vsftpd/ --查看vsftpd的配置 ...
- CentOS7下配置FTP服务
1.参考教程: 腾讯云开发者实验室:基于 CentOS 搭建 FTP 文件服务 Linux就该这么学>:第11章 使用Vsftpd服务传输文件 (需要自己百度) 2.实验环境: VMware 1 ...
- (7)centos7安装配置ftp服务器
1.安装vsftpd yum install vsftpd -y 2.设置开机启动vsftpd ftp服务 systemctl enable vsftpd.service 3.启动vsftpd服务 s ...
- CentOS7安装配置FTP服务器
假设我们有以下要求 路径 权限 备注 /ftp/open 公司所有人员包括来宾均可以访问 只读 /ftp/private 仅允许Alice.Jack.Tom三个人访问 Alice.Jack只允许下载, ...
- Linux 安装配置 FTP 服务 (vsftpd)
1. 安装 vsftpd yum install vsftpd -y 2. 创建用户 record adduser -s /bin/nologin -d /var/RecordFile/ record ...
- Centos7安装配置NFS服务和挂载
现在有3台服务器 s1(主),s2(从), s3(从)需要实现文件实时同步,我们可以安装Nfs服务端和客户端来实现! 一.安装 NFS 服务器所需的软件包: 1 yum install -y nf ...
- CentOS7系列--2.1CentOS7中安装配置NTP服务
CentOS7安装配置NTP服务 NTP服务是时间同步服务 1. 安装NTPd [root@centos7 ~]# yum install -y ntp [jack@centos7 ~]$ vi /e ...
- 基于【CentOS-7+ Ambari 2.7.0 + HDP 3.0】搭建HAWQ数据仓库——安装配置NTP服务,保证集群时间保持同步
一.所有节点上使用yum安装配置NTP服务yum install ntp -y 二.选定一台节点作为NTP server, 192.168.58.11修改/etc/ntp.conf vim /etc/ ...
- centos7中搭建ftp服务
博客搬家: centos7中搭建ftp服务 最近想和同学共享一些文件资源,于是在实验室服务器上搭建个ftp服务,本博客记录一下配置的流程.过程基本是参照别人的方法来做的,博客也是在别人博客基础上修改的 ...
随机推荐
- 【IDEA】转大小写快速操作
需求场景: 快速修改一些字符全部变成大写,或者小写 例如修改SQL语句,部分字段大写,部分字段小写,需要统一 快捷键: [Ctrl + Shift + U] 演示案例: SELECT ( (SELEC ...
- 台式机电脑散热之狂想曲——主机机箱散热的另类方法(纯空想中ing)
本博文是一篇狂想曲,之所以叫狂想曲是因为本文只是博主在无聊时突发奇想,而且仅停留于想的阶段,所以本文内容不用太过认真. 事情是这样的,博主有一台式机,有事没事的就喜欢宅在宿舍里面,有时候还能偶然用这台 ...
- Two Sided Cards 题解
前言 五一网课的例题,但是网上没有详细的题解(真的连题解都找不到啊),所以来写一篇,就当攒 RP 了.题目可以在这里提交.原题是 TopCoder - 10947,但是有了账号也交不了? 题目简述 有 ...
- 中电信翼康济世数据中台基于Apache SeaTunnel构建数据集成平台经验分享
作者 | 中电信翼康工程师 代来编辑 | Debra Chen 一. 引言 Apache SeaTunnel作为一个高性能.易用的数据集成框架,是快速落地数据集成平台的基石.本文将从数据中台战略背景. ...
- BST二叉查找树的接口设计
/*************************************************************************************************** ...
- stm32g070 usart 中断问题: 开启接收中断 RXNEIE 需要注意ISR的错误类型,否则会进入中断。
usart 中断问题: 开启接收中断 RXNEIE 需要注意ISR的错误类型,否则会进入中断. 调试时发现,如果ISR的ORE和FE置位,而此时要是使能RX中断(RXNEIE置位)就会进入中断复位程序 ...
- 如何将Linux的NIC 名称更改为 eth0 而不是 enps33 或 enp0s25,只要几秒钟
概述 我们使用Linux系统,网卡名称通常都是eth0,但是有一些新的linux发行版,网卡名字 enps33 或 enp0s25. peng@ubuntu:~$ ifconfig ens33 Lin ...
- autorun.inf 配置
autorun.inf 文件是一个配置文件,通常用于可移动磁盘(如 USB 驱动器和 CD/DVD)来自动执行某些操作或配置一些设置.当插入可移动磁盘时,Windows 会读取 autorun.inf ...
- YuebonCore:基于.NET8开源、免费的权限管理及快速开发框架
前言 今天大姚给大家分享一款基于.NET8开源.免费(MIT License)功能强大的权限管理及快速开发框架,支持前后端分离,项目架构易于扩展,是中小企业的首选:YuebonNetCore. 核心设 ...
- Android升 Androidx 语系切换失效
背景: 一个很旧的Android项目,android升androidx 切换语系失败,debug的时候,传的语系值是对的,但是确实没有国际化效果 原因: 经过一番学习,原因是使用 implementa ...