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

相关文章

MySQL中的交叉连接、自然连接和内连接查询详解

《MySQL中的交叉连接、自然连接和内连接查询详解》:本文主要介绍MySQL中的交叉连接、自然连接和内连接查询,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、引入二、交php叉连接(cross join)三、自然连接(naturalandroid join)四

Pyserial设置缓冲区大小失败的问题解决

《Pyserial设置缓冲区大小失败的问题解决》本文主要介绍了Pyserial设置缓冲区大小失败的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录问题描述原因分析解决方案问题描述使用set_buffer_size()设置缓冲区大小后,buf

PyInstaller打包selenium-wire过程中常见问题和解决指南

《PyInstaller打包selenium-wire过程中常见问题和解决指南》常用的打包工具PyInstaller能将Python项目打包成单个可执行文件,但也会因为兼容性问题和路径管理而出现各种运... 目录前言1. 背景2. 可能遇到的问题概述3. PyInstaller 打包步骤及参数配置4. 依赖

resultMap如何处理复杂映射问题

《resultMap如何处理复杂映射问题》:本文主要介绍resultMap如何处理复杂映射问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录resultMap复杂映射问题Ⅰ 多对一查询:学生——老师Ⅱ 一对多查询:老师——学生总结resultMap复杂映射问题

鸿蒙中Axios数据请求的封装和配置方法

《鸿蒙中Axios数据请求的封装和配置方法》:本文主要介绍鸿蒙中Axios数据请求的封装和配置方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录1.配置权限 应用级权限和系统级权限2.配置网络请求的代码3.下载在Entry中 下载AxIOS4.封装Htt

解决SpringBoot启动报错:Failed to load property source from location 'classpath:/application.yml'

《解决SpringBoot启动报错:Failedtoloadpropertysourcefromlocationclasspath:/application.yml问题》这篇文章主要介绍... 目录在启动SpringBoot项目时报如下错误原因可能是1.yml中语法错误2.yml文件格式是GBK总结在启动S

Spring中配置ContextLoaderListener方式

《Spring中配置ContextLoaderListener方式》:本文主要介绍Spring中配置ContextLoaderListener方式,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录Spring中配置ContextLoaderLishttp://www.chinasem.cntene

java实现延迟/超时/定时问题

《java实现延迟/超时/定时问题》:本文主要介绍java实现延迟/超时/定时问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Java实现延迟/超时/定时java 每间隔5秒执行一次,一共执行5次然后结束scheduleAtFixedRate 和 schedu

python连接本地SQL server详细图文教程

《python连接本地SQLserver详细图文教程》在数据分析领域,经常需要从数据库中获取数据进行分析和处理,下面:本文主要介绍python连接本地SQLserver的相关资料,文中通过代码... 目录一.设置本地账号1.新建用户2.开启双重验证3,开启TCP/IP本地服务二js.python连接实例1.

idea maven编译报错Java heap space的解决方法

《ideamaven编译报错Javaheapspace的解决方法》这篇文章主要为大家详细介绍了ideamaven编译报错Javaheapspace的相关解决方法,文中的示例代码讲解详细,感兴趣的... 目录1.增加 Maven 编译的堆内存2. 增加 IntelliJ IDEA 的堆内存3. 优化 Mave