Ubuntu16.04 安装与配置Ftp服务器(解决被动模式无法正常连接问题)

本文主要是介绍Ubuntu16.04 安装与配置Ftp服务器(解决被动模式无法正常连接问题),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1 Ftp服务器的安装

如果之前配置过ftp服务器,但无法启动服务,那么本是配置出现了错误,那么可先完全卸载后再进行安装。

sudo apt-get install vsftpd
sudo vsftpd -v          // 检查是否安装 

如果安装会出现:vsftpd: version 3.0.3

2 Ftp服务器的配置

sudo vim /etc/vsftpd.conf   // 修改配置文件 

vsftpd.conf文件如下:

listen=NO                 //是否开启监听ipv4和ipv6数据      
listen_ipv6=YES          //是否开启监听ipv6数据
​
# Allow anonymous FTP? (Disabled by default).
anonymous_enable=NO      //是否允许匿名登陆,无需密码
​
# Uncomment this to allow local users to log in.
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         //设置本地用户默认要减免的权限
​
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES       //目录消息,能够给远程登陆的用户发送目录
#
# If enabled, vsftpd will display directory listings with the time
# in  your  local  time  zone.  The default is to display GMT. The
# times returned by the MDTM FTP command are also affected by this
# option.
use_localtime=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    //确认连接传输的端口号为20
​
# You may override where the log file goes if you like. The default is shown
# below.
xferlog_file=/var/log/vsftpd.log    //日志文件存放位置
#
# 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 fully customise the login banner string:
ftpd_banner=Welcome to FTP service.  //在使用shell时登陆那么会发送欢迎语
​
​
# 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        //白名单路径,若无这个文件需要自己创建
​
# This option should be the name of a directory which is empty.  Also, the
# directory should not be writable by the ftp user. This directory is used
# as a secure chroot() jail at times vsftpd does not require filesystem
# access.
secure_chroot_dir=/var/run/vsftpd/empty
#
# This string is the name of the PAM service vsftpd will use.
# pam_service_name=vsftpd
pam_service_name=ftp            //此处ubuntu的系统需要改为ftp
​
# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO                 
​
#
# Uncomment this to indicate that vsftpd use a utf8 filesystem.
utf8_filesystem=YES       //编码统一为utf8编码,可以识别中文,防止乱码
​
local_root=/home/ftpuser //本地用户默认访问的目录
​
pasv_enable=YES  //Ftp服务器的工作模式,此时为被动模式, 如果设置port_enable=YES,就表示主动模式
pasv_min_port=6000  //在PASV模式下,建立数据传输所可以使用port范围的下界
pasv_max_port=7000  //在PASV模式下,建立数据传输所可以使用port范围的上界,把端口范围设在比较高的一段范围内,比如50000-60000,将有助于安全性的提高。

补充:(未出现在vsftpd.conf配置文件中的常用参数)

guest_enable=YES  
guest_username=ftp  guest用户名,即登陆不是匿名用户的用户,具有guest用户身份  
local_root=/var/ftp  
anon_root=/var/ftp  以上两个选项为本地用户和匿名用户默认访问的目录  
#pasv_enable=YES  
#port_enable=YES  以上两个选项是FTP服务器的工作模式,两者只能出现一个,而且另一个必须注释掉。  
use_localtime=YES  是否使用本机时间,若设置NO时,仅使用格林尼治时间。由于北京时间和格林尼治时间有8小时时差,所以建议设置为YES  
Idle_session_timeout=300  客户端若在300秒之内没有任何操作,则服务器自动断开。  
max_clinet=0  最大连接数量(stand-alone模式下)  
max_per_ip=0  每个客户端最大连接ftp服务器的连接数  
local_max_rate=0  本地用户登陆FTP服务器最大传输速率,单位为字节/秒  
anon_max_rate=0  匿名用户登陆FTP服务器最大传输速率,单位为字节/秒 
allow_writeable_chroot=YES解决500 OOPS: vsftpd: refusing to run with writable root inside chroot (),也可以使用命令sudo chmod a-w /home/user去除用户主目录的写权限,注意把目录替换成你自己的

3 添加并设置Ftp用户

sudo mkdir /home/ftpuser
sudo useradd ftpuser -d /home/ftpuser -m
sudo passwd ftpuser
sudo chmod 777 -R /home/ftpuser
sudo usermod -s /sbin/nologin ftpuser

4 开启或重启vsftp服务

sudo service vsftpd stop     //停止vsftpd服务
sudo service vsftpd start    //开启vsftpd服务
sudo service vsftpd restart  //重启vsftpd服务

5 服务器开启Ftp端口范围

如果设置pasv_min_portpasv_max_port,需要在服务器配置一下安全组的入口规则,否则通过浏览器的ftp请求是无法访问的。注意端口号要和自己设置的范围保持一直,图片中显示没有一致。

  • 阿里云服务器配置安全组

 

  • 腾讯云服务器配置安全组

6 Ftp服务器测试

  • 浏览器访问

  • windows资源管理器访问

     

         

  • windows终端cmd访问

7 遇到的各种坑

       有的猿友可能会遇到奇葩的问题,我个人都遇到过(浪费三天时间),同样的部署在不同类型的服务器部署,会存在被动模式死活连接不上的问题。这是因为如果购买的服务器使用的是专有网络,是不区分公网和内网,修改安全组也没有这个区分选项,但采用经典网络的是由公网和内网的区分,所以就会存在这样的差异。比如:

       分析之后发现,采用ftp被动模式登录成功,服务端映射给客户端的ip地址是私有的,所以客户端无法和服务器建立连接关系,也就意味着ftp命令无法使用,只能采取主动模式。解决方案如下:

listen=NO           ===》 修改为listen=YES    
listen_ipv6=YES     ===》 修改为listen_ipv6=NO   
​
pasv_address=111.231.34.12   // 说明一定要是公网IP,如果不添加,返回被动模式的ip是0.0.0.0

 

这篇关于Ubuntu16.04 安装与配置Ftp服务器(解决被动模式无法正常连接问题)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/556465

相关文章

Kotlin Map映射转换问题小结

《KotlinMap映射转换问题小结》文章介绍了Kotlin集合转换的多种方法,包括map(一对一转换)、mapIndexed(带索引)、mapNotNull(过滤null)、mapKeys/map... 目录Kotlin 集合转换:map、mapIndexed、mapNotNull、mapKeys、map

nginx中端口无权限的问题解决

《nginx中端口无权限的问题解决》当Nginx日志报错bind()to80failed(13:Permissiondenied)时,这通常是由于权限不足导致Nginx无法绑定到80端口,下面就来... 目录一、问题原因分析二、解决方案1. 以 root 权限运行 Nginx(不推荐)2. 为 Nginx

解决1093 - You can‘t specify target table报错问题及原因分析

《解决1093-Youcan‘tspecifytargettable报错问题及原因分析》MySQL1093错误因UPDATE/DELETE语句的FROM子句直接引用目标表或嵌套子查询导致,... 目录报js错原因分析具体原因解决办法方法一:使用临时表方法二:使用JOIN方法三:使用EXISTS示例总结报错原

Windows环境下解决Matplotlib中文字体显示问题的详细教程

《Windows环境下解决Matplotlib中文字体显示问题的详细教程》本文详细介绍了在Windows下解决Matplotlib中文显示问题的方法,包括安装字体、更新缓存、配置文件设置及编码調整,并... 目录引言问题分析解决方案详解1. 检查系统已安装字体2. 手动添加中文字体(以SimHei为例)步骤

JAVA中安装多个JDK的方法

《JAVA中安装多个JDK的方法》文章介绍了在Windows系统上安装多个JDK版本的方法,包括下载、安装路径修改、环境变量配置(JAVA_HOME和Path),并说明如何通过调整JAVA_HOME在... 首先去oracle官网下载好两个版本不同的jdk(需要登录Oracle账号,没有可以免费注册)下载完

SpringSecurity整合redission序列化问题小结(最新整理)

《SpringSecurity整合redission序列化问题小结(最新整理)》文章详解SpringSecurity整合Redisson时的序列化问题,指出需排除官方Jackson依赖,通过自定义反序... 目录1. 前言2. Redission配置2.1 RedissonProperties2.2 Red

nginx 负载均衡配置及如何解决重复登录问题

《nginx负载均衡配置及如何解决重复登录问题》文章详解Nginx源码安装与Docker部署,介绍四层/七层代理区别及负载均衡策略,通过ip_hash解决重复登录问题,对nginx负载均衡配置及如何... 目录一:源码安装:1.配置编译参数2.编译3.编译安装 二,四层代理和七层代理区别1.二者混合使用举例

Java JDK1.8 安装和环境配置教程详解

《JavaJDK1.8安装和环境配置教程详解》文章简要介绍了JDK1.8的安装流程,包括官网下载对应系统版本、安装时选择非系统盘路径、配置JAVA_HOME、CLASSPATH和Path环境变量,... 目录1.下载JDK2.安装JDK3.配置环境变量4.检验JDK官网下载地址:Java Downloads

SQL server数据库如何下载和安装

《SQLserver数据库如何下载和安装》本文指导如何下载安装SQLServer2022评估版及SSMS工具,涵盖安装配置、连接字符串设置、C#连接数据库方法和安全注意事项,如混合验证、参数化查... 目录第一步:打开官网下载对应文件第二步:程序安装配置第三部:安装工具SQL Server Manageme

C#连接SQL server数据库命令的基本步骤

《C#连接SQLserver数据库命令的基本步骤》文章讲解了连接SQLServer数据库的步骤,包括引入命名空间、构建连接字符串、使用SqlConnection和SqlCommand执行SQL操作,... 目录建议配合使用:如何下载和安装SQL server数据库-CSDN博客1. 引入必要的命名空间2.