Linux系统搭建FTP服务器

news/2025/2/14 5:56:24/
  1. 安装vsftpd

yum -y install vsftpd
  1. 添加FTP用户

  1. 方式1、添加只允许通过ftp访问的用户

useradd -d /home/ftp ftp_user #-d指定用户登录时的启始目录
  1. 方式2、允许用户登录操作系统

usermod -d /home/ftp -s /bin/bash ftp_user #-s指定用户登入后所使用的shell
  1. 设置用户登录密码

passwd ftp_pwd
  1. 修改配置文件(文件位置/etc/vsftpd/vsftpd.conf,修改时注意用户权限)

# 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 #是有有写权限# 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)
# 多数情况下,希望限制ftp用户只能在其主目录下活动,需要配置如下三个属性
chroot_local_user=YES #默认值NO,是否将所有用户限制在主目录,当为NO时,ftp用户可以向上切换目录
chroot_list_enable=YES #是否启用例外用户名单
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list #例外用户名单,限制主目录属性跟chroot_local_user相反# 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=YES
#
# 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 !!#IPv4和IPv6只能监听其中之一listen_ipv6=NOuserlist_enable=YES # 开启“名单列表”限制功能
userlist_deny=NO # 设置“名单列表”为“白名单”,仅指定列表中的用户允许使用FTP登录
userlist_file=/etc/vsftpd/user_list    # “名单列表”对应的文件pasv_min_port=30001    #传输端口
pasv_max_port=31000    #传输端口
  1. 主动模式与被动模式

  1. 主动模式-连接过程

  1. 客户端与服务器的21端口建立连接

  1. 客户端开放一个随机高位端口端口(1024以上),用于接收数据

  1. 客户端发送PORT主动模式命令给服务器21端口,其中PORT命令包括客户端用于接收数据的端口号

  1. 服务器通过20端口和客户端的新开放端口进行连接,并给客户端发送数据

  1. 被动模式-连接过程

  1. 客户端与服务器的21端口建立连接

  1. 客户端发送PASV被动模式命令给服务器21端口

  1. 服务器打开一个随机高位端口用于传输数据(1024以上),并通知客户端

  1. 客户端连接到服务器新开放的端口进行数据传输

  1. 由于linux服务器有防火墙限制,被动模式时,传输端口不确定,导致防火墙开放端口不确定,所以在配置中指定被动模式时端口上下限,然后配置防火墙规则

iptables -I INPUT -p tcp --dport 30001:31000 -j ACCEPT
iptables -I OUTPUT -p tcp --dport 30001:31000 -j ACCEPT
  1. 配置被动模式,可以直接方便通过ftp客户端软件连接。

  1. 好用的linux问题网站:https://unix.stackexchange.com/

  1. 补充问题:

2023-03-25:ftp时报错:421 Service not available
解决方案:/etc/hosts.allow中添加允许访问的vsftpd:xxx.xxx.xxx.xxx


http://www.ppmy.cn/news/32133.html

相关文章

C语言实现学生成绩管理系统思考

学生成绩管理系统思考 作业要求: 目录 思路 基本函数 学习理解大佬的代码: 完成作业: 思路 学生成绩管理系统,首先要初始化系统, 用C语言做学生实验管理系统要求实现对某班学生3门课程(包括语文、数…

Linux基本命令——操作演示

Linux基本命令——操作演示Linux的目录结构Linux命令入门目录切换相关命令(cd/pwd)相对路径、绝对路径和特殊路径符创建目录命令(mkdir)文件操作命令part1 (touch、cat、more)文件操作命令part2 (cp、mv、rm)查找命令 …

程序员必会技能—— 使用日志

目录 1、为什么要使用日志 2、自定义日志打印 2.1、在程序中得到日志对象 2.2、使用日志对象打印日志 2.3、日志格式 3、日志的级别 3.1、日志级别的分类 3.2、日志级别的设置 4、持久化日志 5、更简单的日志输出——lombok 5.1、如何在已经创建好的SpringBoot项目中添加…

计算机网络复习

什么是DHCP和DNS DNS(Domain Name System,域名系统),因特网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而不用去记住能够被机器直接读取的IP数串。通过主机名,最终得到该主机名对应的…

Java每日一练(20230313)

目录 1. 字符串统计 ★ 2. 单词反转 ★★ 3. 俄罗斯套娃信封问题 ★★★ 🌟 每日一练刷题专栏 C/C 每日一练 ​专栏 Python 每日一练 专栏 Java 每日一练 专栏 1. 字符串统计 编写一个程序,对于输入的一段英语文本,可以统计&#…

【C++笔试强训】第三十一天

🎇C笔试强训 博客主页:一起去看日落吗分享博主的C刷题日常,大家一起学习博主的能力有限,出现错误希望大家不吝赐教分享给大家一句我很喜欢的话:夜色难免微凉,前方必有曙光 🌞。 选择题 &#x…

如何保证Redis缓存和数据库一致性?

想要保证缓存与数据库的双写一致,一共有4种方式: 先更新缓存,再更新数据库; 先更新数据库,再更新缓存; 先删除缓存,再更新数据库; 先更新数据库,再删除缓存。 我们需要做…

进程间通信IPC

进程间通信IPC (InterProcess Communication) 一、进程间通信的概念 每个进程各自有不同的用户地址空间,任何一个进程的全局变量在另一个进程中都看不到,所以进程之间要交换数据必须通过内核,在内核中开辟一块缓冲区,进程1把数据…