Linux下安装并配置FTP文件服务器

2023-05-16

一、安装vsftpd

1. 运行如下代码安装vsftpd

yum install -y vsftpd

2. 运行以下命令设置FTP服务开机自启动

systemctl enable vsftpd.service

3. 运行以下命令启动FTP服务

systemctl start vsftpd.service

4. 运行以下命令查看FTP服务监听的端口

netstat -antup | grep ftp

二、配置vsftpd

1. 运行以下命令为FTP服务创建一个Linux用户。本示例中,该用户名为ftptest

adduser ftptest

3. 运行以下命令创建一个供FTP服务使用的文件目录

mkdir /mydata/ftp

4. 运行以下命令更改/var/ftp/test目录的拥有者为ftptest

chown -R ftptest:ftptest /mydata/ftp

5. 修改vsftpd.conf配置文件

1) 运行命令打开配置文件
vim /etc/vsftpd/vsftpd.conf
2) 根据如下内容,修改或添加相关配置参数
# 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=YES
#
# 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_enable=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=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
#除下面提及的参数外,其他参数保持默认值即可。
#修改下列参数的值
#禁止匿名登录FTP服务器
anonymous_enable=NO
##允许本地用户登录FTP服务器
local_enable=YES
##监听IPv4 sockets
listen=YES
#在行首添加#注释掉以下参数,关闭监听IPv6 sockets
listen_ipv6=NO
#添加下列参数
#设置本地用户登录后所在目录
local_root=/mydata/ftp
#全部用户被限制在主目录
chroot_local_user=YES
#启用例外用户名单
chroot_list_enable=YES
#指定例外用户列表文件,列表中用户不被锁定在主目录
chroot_list_file=/etc/vsftpd/chroot_list
#开启被动模式
pasv_enable=YES
allow_writeable_chroot=YES
#Linux实例公网IP
pasv_address= ******
#设置被动模式下,建立数据传输可使用的端口范围的最小值
pasv_min_port=40000
#设置被动模式下,建立数据传输可使用的端口范围的最大值
pasv_max_port=40100
userlist_deny=NO
userlist_file=/etc/vsftpd/user_list

建议您把端口范围设置在一段比较高的范围内,例如50000~50010,有助于提高访问FTP服务器的安全性。

3)创建chroot_list文件,并在文件中写入例外用户名单
vim /etc/vsftpd/chroot_list
4)运行以下命令重启vsftpd服务
systemctl restart vsftpd.service

三、解决无法创建文件、无法连接到服务问题

1. 暂时关闭防火墙测试

systemctl stop firewalld.service

2. 暂时关闭SELINUX安全系统

setenforce 0

3. centos7防火墙操作

firewall-cmd --permanent --add-port=22/tcp (开放22端口)
firewall-cmd --reload
sudo systemctl start firewalld
sudo systemctl stop firewalld
sudo systemctl status firewalld

四、vsftp配置文件及参数说明

1. /etc/vsftpd目录下文件说明如下:

  • /etc/vsftpd/vsftpd.conf 是vsftpd的核心配置文件。
  • /etc/vsftpd/ftpusers 是黑名单文件,此文件中的用户不允许访问FTP服务器。
  • /etc/vsftpd/user_list是白名单文件,此文件中的用户允许访问FTP服务器。

2. 配置文件vsftpd.conf参数说明如下:

参数说明
pasv_enable=YES开启被动模式
pasv_enable=NO开启主动模式
不设置该参数配置文件中默认不设置该参数,表示使用被动模式

3. 用户登录控制参数说明如下表所示:

参数说明
anonymous_enable=YES接受匿名用户
no_anon_password=YES匿名用户login时不询问口令
anon_root=(none)匿名用户主目录
local_enable=YES接受本地用户
local_root=(none)本地用户主目录

4. 用户权限控制参数说明如下表所示:

参数说明
write_enable=YES可以上传文件(全局控制)
local_umask=022本地用户上传的文件权限
file_open_mode=0666上传文件的权限配合umask使用
anon_upload_enable=NO匿名用户可以上传文件
anon_mkdir_write_enable=NO匿名用户可以建目录
anon_other_write_enable=NO匿名用户修改删除
chown_username=lightwiter匿名上传文件所属用户名
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Linux下安装并配置FTP文件服务器 的相关文章

  • 如何通过代理将套接字连接到http服务器?

    最近 我使用 C 语言编写了一个程序 用于连接到本地运行的 HTTP 服务器 从而向该服务器发出请求 这对我来说效果很好 之后 我尝试使用相同的代码连接到网络上的另一台服务器 例如 www google com 但我无法连接并从网络中的代理
  • CentOS目录结构是树形的吗?

    CentOS 上有相当于树的东西吗 如果你的 Centos 系统上没有安装 tree 无论如何我通常建议服务器设置使用最小安装磁盘 你应该在命令行中输入以下内容 yum install tree y 如果没有安装 那是因为您没有正确的存储库
  • 为 Linux 安装 R 包时出错

    我试图在 R 3 3 上安装一个名为 rgeos 的包 但是当我输入 install packages rgeos 但它返回给我以下错误 其他包也会发生同样的情况 但不是所有包 gt installing source package rg
  • 如何从linux命令行运行.exe可执行文件? [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我在 Windows 中有一个 abc exe 可执行文件 我可以使用 DOS 命令提示来执行此应用程序 并为其提供一些运行时变量 我想从
  • 如何成功使用RDAP协议代替whois

    我对新的 RDAP 协议有点困惑 也不知道何时进一步追求它有意义 在我看来 每个人都同意它是 whois 的继承者 但他们的数据库似乎是空的 在 ubuntu 上我尝试了 rdapper nicinfo 甚至他们的 RESTful API
  • 如何获取 linux 实用程序 tail 的源代码?

    这个命令确实非常有用 但是我可以在哪里获取源代码以查看内部发生的情况 thanks tail 实用程序是 Linux 上 coreutils 的一部分 源压缩包 ftp ftp gnu org gnu coreutils coreutils
  • 如何使用AWK脚本检查表的所有列数据类型? [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 在这里 我正在检查表中第一列的数据类型 但我想知道AWK中表的所有列数据类型 我尝试过 但只能获得一列数据类型 例如 Column 1
  • 无法安装 WWW::Curl::Easy: SZBALINT/WWW-Curl-4.17.tar.gz : make NO

    我正在尝试在我的 Fedora 26 机器上安装 WWW Curl Easy gcc c I usr include D REENTRANT D GNU SOURCE O2 g pipe Wall Werror format securit
  • 为什么在 Linux 上字符串文字的内存地址与其他字符串文字的内存地址如此不同?

    我注意到字符串文字在内存中的地址与其他常量和变量 Linux 操作系统 非常不同 它们有许多前导零 未打印 Example const char h Hi int i 1 printf p n void h printf p n void
  • Linux 中热插拔设备时检测设备是否存在

    我正在运行 SPIcode http lxr free electrons com source drivers spi spi omap2 mcspi c在熊猫板上 我想知道其中的哪个功能code http lxr free electr
  • 如何不断刷新屏幕并实时更新[关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我想在linux上写一个C程序 不断刷新屏幕并实时更新 例如类似于top终端中的命令 谁能指出我正确的方向 为了保持它跨终端类型的可移
  • 如何以编程方式从Linux中的进程名称获取进程ID

    在我的项目中 我们使用 ACE 自适应通信环境 中间件来编写可在 Windows 和 Linux 上运行的独立于操作系统的代码 要求是从进程名称中获取进程 ID 由于 ACE 不支持这一点 因此我们必须使用特定于平台的宏来分离 Window
  • 劫持系统调用

    我正在编写一个内核模块 我需要劫持 包装一些系统调用 我正在暴力破解 sys call table 地址 并使用 cr0 来禁用 启用页面保护 到目前为止一切顺利 一旦完成 我将公开整个代码 因此如果有人愿意 我可以更新这个问题 无论如何
  • 服务器响应 PASV 命令返回的地址与建立 FTP 连接的地址不同

    System Net WebException 服务器响应 PASV 命令返回的地址与建立 FTP 连接的地址不同 在 System Net FtpWebRequest CheckError 在 System Net FtpWebReque
  • Linux shell 脚本中的 while 循环超时

    这工作正常 无限循环 while TRUE do printf done 我在尝试着timeout this while loop与timeout命令 所有这些都不起作用 timeout 5 while TRUE do printf don
  • 在 Linux 上的 Python 中使用受密码保护的 Excel 工作表

    问题很简单 我每周都会收到一堆受密码保护的 Excel 文件 我必须解析它们并使用 Python 将某些部分写入新文件 我得到了文件的密码 当在 Windows 上完成此操作时 处理起来很简单 我只需导入 win32com 并使用 clie
  • 如何制作和应用SVN补丁?

    我想制作一个SVN类型的补丁文件httpd conf这样我就可以轻松地将其应用到其他主机上 If I do cd root diff Naur etc httpd conf httpd conf original etc httpd con
  • 是否可以使用流上下文在 PHP 下使用 FTPS?

    我了解到使用ftpsPHP for Windows 下的 ftp ssl connect 很困难 您被要求进入构建自己的二进制文件以包括 Open SSL 的漫长旅程 我找到了以下建议phpseclib http phpseclib sou
  • 如何模拟ARM处理器运行环境并加载Linux内核模块?

    我尝试加载我的vmlinux into gdb并使用 ARM 内核模拟器 但我不明白为什么我会得到Undefined target command sim 这是外壳输出 arm eabi gdb vmlinux GNU gdb GDB 7
  • 在 Linux 中禁用历史记录 [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 要在 Linux 环境中禁用历史记录 我执行了以下命令 export HISTFILESIZE 0 export HISTSIZE 0 u

随机推荐

  • 某项目因为多次流标导致实际项目时间严重压缩,我该咋办?

    问题 xff1a 某政府项目 xff0c 三个月前就开始招标 xff0c 因各种原因 xff0c 流标三次 xff0c 导致时间拖太长 原计划一期工期三个月 43 xff0c 1月底上线 xff0c 但因为招投标影响直到一个月前签订了合同
  • ROS创建工作空间及功能包流程总结整理(python)

    ROS创建工作空间及功能包流程总结整理 xff08 python xff09 参考资料 xff1a B站赵虚左 xff1a https www bilibili com video BV1Ci4y1L7ZZ p 61 19 amp vd s
  • ROS自定义发布消息类型

    ROS自定义发布消息类型 xff1a 在 ROS 通信协议中 xff0c 数据载体是一个较为重要组成部分 xff0c 在上一案例中 xff0c ROS 中通过 std msgs 封装了一些原生的数据类型 比如 String Int32 In
  • ROS服务通信:自定义数据文件以及服务端和客户端代码编写流程及步骤详解

    ROS服务通信具体实现流程 demo xff1a 实现两个整型数相加求和 xff0c 客户端发送两个整型数 xff0c 服务端对其求和 服务通信也需要自定义服务数据类型 xff0c 即自定义srv文件 xff0c 该过程和自定义msg文件非
  • ROS TF静态坐标变换实现

    ROS TF静态坐标变换实现 法一 xff1a 编码实现 发布方代码实现 xff1a 创建功能包并添加依赖 catkin create pkg tf static roscpp rospy std msgs tf2 tf2 ros tf2
  • ROS:Gazebo导入自定义环境

    Gazebo导入自定义环境 之前的案例gazebo中导入的是一个空世界empty world xff0c 这里会介绍如何导入房屋数目等自定义的环境 xff08 1 xff09 启动 gazebo 打开构建面板 xff0c 绘制仿真环境 xf
  • ROS导航实现:SLAM建图(slam_gmapping)与保存(map_server)

    导航实现 xff1a SLAM建图 先安装相关的ROS功能包 安装 gmapping 包 用于构建地图 sudo apt install ros lt ROS版本 gt gmapping 安装地图服务包 用于保存与读取地图 sudo apt
  • ROS导航实现:amcl定位

    ROS导航实现 xff1a amcl定位 xff08 1 xff09 首先编写启动amcl的launch文件 xff0c 这里建议复制粘贴模板 xff0c 再修改相关的参数即可 xff0c 步骤如下 xff1a 主目录下进入amcl文件 r
  • ROS导航实现之路径规划

    导航实现之路径规划 move base 功能包提供了基于动作 action 的路径规划实现 xff0c move base 可以根据给定的目标点 xff0c 控制机器人底盘运动至目标位置 xff0c 并且在运动过程中会连续反馈机器人自身的姿
  • 创建个人网站(github pages)并将站点一键托管到Github

    创建个人网站 xff08 github pages xff09 并将站点一键托管到Github 内容 xff1a 使用网站生成器mkdocs将markdown文件生成wiki站点并挂载到github的流程总结 亮点 xff1a 个人网站一键
  • 视觉SLAM十四讲(第2版)总结

    最近看完了 视觉SLAM十四讲 xff08 第2版 xff09 xff1a 从理论到实践 xff08 高翔等著 xff09 xff0c 原书分两部分 xff0c 先介绍了数学基础 xff0c 然后介绍了具体的SLAM实践 xff0c 非常适
  • 我的公众号 - 豆芽儿 软件研发人才生长社区

    为你系统分享敏捷开发 项目管理 需求分析 软件设计 UML 中层领导力 CMMI IT职场 ACP 软考 PMP等 高大上 的实用知识 xff0c 帮助你进阶为高端人才 xff01
  • Openblas 下载和使用方法

    Openblas 下载及使用 环境 xff1a 平台 xff1a Ubuntu 20 04 xff0c Orin xff1a Arm Cortex A78AE v8 2 64 bit 步骤 xff1a 1 去github 下载openbla
  • FreeRTOS学习记录

    FreeRTOS学习记录 前言FreeRTOS学习记录在STM32CubeMX中配置FreeRTOS 前言 本人小白 xff0c 最近学习了FreeRTOS操作系统 xff0c 打算做一点记录 学习的过程中虽然做了点练习 xff0c 不过都
  • 如何给华三交换机恢复出厂设置及命令

    如何给华三交换机恢复出厂设置及命令 在前几天 xff0c 上级单位线路重新规划 xff0c 需要我们将单位的线路进行改造 xff0c 这就涉及到了网络设备的重新配置 经查看 xff0c 上级接入交换机的业务端口配置为access xff0c
  • 解决Linux下Docker下载安装太慢

    卸载先前版本 yum remove docker docker span class token operator span client docker span class token operator span client span
  • sqlyong连接docker中的mysql 失败can‘t connect to MySQL server on (*******:3306)

    解决sqlyong连接docker中myslq失败 xff1a 一 查看mysql是否运行docker ps 二 查看mysql端口映射是否与连接相符 三 进入mysql容器查看是否能够进行本地连接docker exec it mysql
  • 解决springboot+webSocket出现404错误

    这是因为websocket创建的bean是由自己来管理的 需要将其创建的bean交给spring管理 创建websocketconfig span class token keyword package span com span clas
  • Bytebuffer源码剖析及实现原理

    Bytebuffer 官方解释A byte buffer xff0c 一个字节缓冲区 一 使用方法 ByteBuffer 初始状态是写模式 使用IO流即可写入数据 如 channel read 如果需要读取ByteBuffer中的数据调用f
  • Linux下安装并配置FTP文件服务器

    一 安装vsftpd 1 运行如下代码安装vsftpd yum install span class token operator span y vsftpd 2 运行以下命令设置FTP服务开机自启动 systemctl enable vs