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

相关文章

Prometheus+cpolar如何在手机上也能监控服务器状态?

《Prometheus+cpolar如何在手机上也能监控服务器状态?》本文强调了通过Cpolar这一内网穿透工具,轻松突破Prometheus仅限于局域网访问的限制,实现外网随时随地访问监控数据,教你... 目录前言1.安装prometheus2.安装cpolar实现随时随地开发3.配置公网地址4.保留固定

windows下安装Nginx全过程

《windows下安装Nginx全过程》文章介绍了HTTP和反向代理服务器的概念,包括正向代理和反向代理的区别,并详细描述了如何安装和配置Nginx作为反向代理服务器... 目录概念代理正向代理反向代理安装基本属性nginx.conf查询结构属性使用运行重启停止总结概念是一个高性能的HTTP和反向代理we

Spring配置扩展之JavaConfig的使用小结

《Spring配置扩展之JavaConfig的使用小结》JavaConfig是Spring框架中基于纯Java代码的配置方式,用于替代传统的XML配置,通过注解(如@Bean)定义Spring容器的组... 目录JavaConfig 的概念什么是JavaConfig?为什么使用 JavaConfig?Jav

Spring Boot Interceptor的原理、配置、顺序控制及与Filter的关键区别对比分析

《SpringBootInterceptor的原理、配置、顺序控制及与Filter的关键区别对比分析》本文主要介绍了SpringBoot中的拦截器(Interceptor)及其与过滤器(Filt... 目录前言一、核心功能二、拦截器的实现2.1 定义自定义拦截器2.2 注册拦截器三、多拦截器的执行顺序四、过

JavaWeb项目创建、部署、连接数据库保姆级教程(tomcat)

《JavaWeb项目创建、部署、连接数据库保姆级教程(tomcat)》:本文主要介绍如何在IntelliJIDEA2020.1中创建和部署一个JavaWeb项目,包括创建项目、配置Tomcat服务... 目录简介:一、创建项目二、tomcat部署1、将tomcat解压在一个自己找得到路径2、在idea中添加

Springboot3统一返回类设计全过程(从问题到实现)

《Springboot3统一返回类设计全过程(从问题到实现)》文章介绍了如何在SpringBoot3中设计一个统一返回类,以实现前后端接口返回格式的一致性,该类包含状态码、描述信息、业务数据和时间戳,... 目录Spring Boot 3 统一返回类设计:从问题到实现一、核心需求:统一返回类要解决什么问题?

springboot的controller中如何获取applicatim.yml的配置值

《springboot的controller中如何获取applicatim.yml的配置值》本文介绍了在SpringBoot的Controller中获取application.yml配置值的四种方式,... 目录1. 使用@Value注解(最常用)application.yml 配置Controller 中

springboot中配置logback-spring.xml的方法

《springboot中配置logback-spring.xml的方法》文章介绍了如何在SpringBoot项目中配置logback-spring.xml文件来进行日志管理,包括如何定义日志输出方式、... 目录一、在src/main/resources目录下,也就是在classpath路径下创建logba

解决idea启动项目报错java: OutOfMemoryError: insufficient memory

《解决idea启动项目报错java:OutOfMemoryError:insufficientmemory》:本文主要介绍解决idea启动项目报错java:OutOfMemoryError... 目录原因:解决:总结 原因:在Java中遇到OutOfMemoryError: insufficient me

maven异常Invalid bound statement(not found)的问题解决

《maven异常Invalidboundstatement(notfound)的问题解决》本文详细介绍了Maven项目中常见的Invalidboundstatement异常及其解决方案,文中通过... 目录Maven异常:Invalid bound statement (not found) 详解问题描述可