vsftpd.confg 常用配置,Beyond Compare 测试可用
  7VQdK9JEqFfw 2023年12月10日 28 0


vsftpd.confg 常用配置,备份一下, 经常配置好久 , 以后直接粘贴即可.
Beyond Compare 测试可用.

# Example config file /etc/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.
#
#
# Run standalone?  vsftpd can run either from an inetd or as a standalone
# daemon started from an initscript.
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.
listen_ipv6=NO
#
# 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
#
# 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.
#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
#
# 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
#
# 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/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 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.
# 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 restrict local users to their home directories.  See the FAQ for
# the possible risks in this before using chroot_local_user or
# chroot_list_enable below.
chroot_local_user=NO
#
# 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=NO
# (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
#
# Customization
#
# Some of vsftpd's settings don't fit the filesystem layout by
# default.
#
# 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=/data/www
#
# This string is the name of the PAM service vsftpd will use.
pam_service_name=vsftpd
#
# 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
#服务器所在公网的ip
pasv_address=22.15.545.45
#服务器开放的端口范围
pasv_min_port=30000
pasv_max_port=30100

给文件夹赋予755权限

sudo chmod -R 755 /data/www

vsftpd.confg 常用配置,Beyond Compare 测试可用_数据


这个配置经过测试在局域网环境下是可以使用的.

如果要跨越路由器 , 那么路由器要开放一些端口 .

vsftpd.confg中设置被动模式的几个端口,

#服务器所在公网的ip
pasv_address=22.15.545.45
#服务器开放的端口范围
pasv_min_port=30000
pasv_max_port=30100

如果提示需要账号密码
那么最好建一个新用户

# 创建ftpa用户,指定此用户的主目录。
# `-d` 选项用于指定用户的主目录;`-s` 选项用于指定用户的默认 shell。
# `/sbin/nologin` 是一个特殊的 shell,它不允许用户登录系统.
# 通常用于限制某些用户只能通过特定的服务(如FTP、SFTP等)进行远程访问,
# 而不能直接登录系统。
#sudo useradd -d /data/www -s /sbin/nologin ftpa
 sudo useradd -d /data/www  ftpa

然后改个密码

passwd ftpa

如果提示

cannot change directory:/home/ftpa

这是因为ftpa用户新建的时候并没有新建 /home/ftpa 目录 那么新建一个这个目录即可, 登录成功后会自动转向到其它目录.

mkdir /home/ftpa

如果提示

530 Login incorrect.
禁止登录了.

是因为 sudo useradd -d /data/www -s /sbin/nologin ftpa 的时候 -s选项禁止登录了.

重新建用户即可

sudo useradd -d /data/www ftpa

如果提示 无法检索文件夹内容,并提示

已发送>PORT 192,168,110,127,255,224
接收>500 Illegal PORT command.

则大概率是端口没开放, 这是主动连接模式. 这样的模式是 :服务端从20端口主动向客户端发起连接,工作过程如下图所示:
第一步中,FTP客户端提交PORT命令并允许服务器来回连它的数据端口(1027端口)。

第二步中,服务器返回确认。

在第三步中,FTP服务器向客户端发送TCP连接请求,目标端口为1027,源端口为20。建立起传输数据的连接。

vsftpd.confg 常用配置,Beyond Compare 测试可用_ubuntu_02

4、被动模式:服务端在指定范围内的某各端口被动等待客户,被动发起连接。

在第一步中,客户端的命令端口与服务器的命令端口建立连接,并发送命令"PASV"。

在第二步中,服务器返回命令"PORT 2024"告诉客户端:服务器用哪各端口监听数据连接。

在第三步中 ,客户端初始化一个从自己的数据端口到到服务器指定的数据端口的数据连接。

在第四步中,服务器给客户端的数据端口返回一个"ACK"响应。

vsftpd.confg 常用配置,Beyond Compare 测试可用_客户端_03

正常情况下, 我们的ftp客户端都是放在内网的, ftp是无法主动访问到我们的客户端的, 除非ftp服务器和客户端在同一个网段下, 或者端口都映射过了才可行. 所以一般是不会使用主动模式的, 基本上都是被动模式. 也即是我们的客户端主动去连接ftp服务器.
Beyond Compare的ftp配置也默认是被动模式

如果提示

2023/12/6 星期三 11:39:26 接收>250 Directory successfully changed.
2023/12/6 星期三 11:39:26 已发送>PASV
2023/12/6 星期三 11:39:26 接收>227 Entering Passive Mode (192,168,1,3,55,93).
2023/12/6 星期三 11:39:26 已发送>LIST

则说明Beyond Compare是在被动模式下运行的. 客户端需要连接ip 192.168.1.3 进行连接. 后面2位,55,93暂时不知道干啥用的

我的云服务器上因为有两个ip, 竟然返回了一个内网ip… 我晕.
那么要告诉vsftpd 被动模式的ip地址是外网ip.

pasv_address=22.15.545.45

那么服务器上的防火墙要保证 172,25,21,182,40,199 这几个端口是可以访问的.

如果卡在了

2023/12/6 星期三 11:39:26 接收>250 Directory successfully changed.
2023/12/6 星期三 11:39:26 已发送>PASV
2023/12/6 星期三 11:39:26 接收>227 Entering Passive Mode (0,0,0,0,55,93).

是因为开启了ipv6的监听, 配置上关闭ipv6的监听, 然后打开listen.不打开listen选项好像不行

listen=YES
listen_ipv6=NO

最后安全建议, ftp用完就关

service vsftpd stop
service vsftpd strat
service vsftpd restrat

则是因为开启了ipv6的原因
我关于ftp的配置觉得下面这篇文章是最好的


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年12月10日 0

暂无评论

推荐阅读
7VQdK9JEqFfw