【linux】Debian10.0配置vsftpd

一、基本步骤【linux】Debian10.0配置vsftpd_第1张图片

在 Debian 10 (Buster) 上要配置 vsftpd (Very

Secure FTP Daemon),请按照以下步骤操作:

1. 安装 vsftpd:

sudo apt update
sudo apt install vsftpd

2. 在启动配置之前,建议备份原始的配置文件:

sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.orig

3. 使用文本编辑器编辑 vsftpd 配置文件:

sudo nano /etc/vsftpd.conf

或者

sudo vi /etc/vsftpd.conf

根据你的喜好选择编辑器。

4. 修改配置文件中的条目来设置你的 FTP 服务器。以下是一些常见配置参数的说明和示例:

- 匿名访问:

anonymous_enable=NO

通常会禁用匿名访问,以提高安全性。

- 本地用户登录:

local_enable=YES

允许本地用户登录。

- 写权限:

write_enable=YES

为已认证用户启用上传/写入权限。

- 本地用户根目录限制 (chroot jail):

chroot_local_user=YES

将用户限制在其主目录中。

- 文件上传的默认权限:

local_umask=022

新上传的文件默认权限设置。

- PASV 模式配置:

pasv_enable=YES
pasv_min_port=40000
pasv_max_port=50000

为 PASV 模式指定端口范围。

- 端口模式支持:

port_enable=YES

允许使用端口模式 (PORT)。

- FTP 用户登录后的欢迎信息:

ftpd_banner=Welcome to My FTP service.

自定义登录后显示的欢迎信息。

5. 保存并关闭配置文件。

6. 重启 vsftpd 服务以应用更改:

sudo systemctl restart vsftpd

7. 如果有防火墙(如 ufw),请确保开放 FTP 所使用的端口:

sudo ufw allow 20/tcp
sudo ufw allow 21/tcp
sudo ufw allow 40000:50000/tcp
sudo ufw reload

8. 确保用户的主目录或指定的 FTP 服务器的根目录具有正确的权限。

如果你打算使用 vsftpd 作为安全 FTP 服务器,并且需要支持 FTPS (FTP over SSL/TLS),你还可以配置 SSL/TLS 相关的设置,如下所示:

- 在 /etc/vsftpd.conf 文件中添加以下行启用 SSL:

ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES

- 设置 SSL 证书和密钥的位置:

rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key

这里使用的是自签证书,对于生产环境,应考虑购买或使用 Let's Encrypt 等服务免费获得证书。

- 重启 vsftpd 使 SSL 配置生效:

sudo systemctl restart vsftpd

以上是基本的 vsftpd 安装和配置步骤。

二、一个配置实例

1. 配置文件/etc/vsftpd.conf :

# 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=NO
#
# 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=YES
#
# 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=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)
#chroot_local_user=YES
#chroot_list_enable=YES
# (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=/var/run/vsftpd/empty
#
# 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

port_enable=YES

2. 重启 vsftpd 服务

sudo systemctl restart vsftpd

3. 测试

用linux系统用户/密码登录,上传文件到/dev/shm目录,再下载文件到本地,传输成功。

三、配置可登录的用户名和密码并指定用户的根目录【linux】Debian10.0配置vsftpd_第2张图片

要配置可登录的用户名和密码并指定用户的根目录,需要按照以下步骤配置 vsftpd

1. 创建 FTP 用户:

   - 创建一个新的系统用户,用于 FTP 登录。

sudo adduser ftpusername

     这将创建一个新用户 ftpusername 并提示你为该用户设置密码。

2. 配置用户的根目录:

   - 可以指定用户的家目录作为FTP的根目录,这通常在创建用户时就设定好了。例如,如果用户是 ftpusername,他们的家目录通常是 /home/ftpusername
   - 如果想改变这个目录或者创建一个特别的FTP根目录,可以使用以下命令:

     sudo mkdir /home/ftp/ftpusername  # 创建FTP根目录
     sudo chown ftpusername:ftpusername /home/ftp/ftpusername  # 将目录所有权分配给用户

   - 更改用户的主目录(如果需要):

sudo usermod -d /home/ftp/ftpusername ftpusername

3. 配置 vsftpd 以使用本地用户认证:

   - 编辑 vsftpd 配置文件 vsftpd.conf,通常位于 /etc/vsftpd.conf

sudo nano /etc/vsftpd.conf

   - 确保以下行未被注释(去掉行首的 #)或者被正确设置:

     local_enable=YES
     chroot_local_user=YES

     这两行的设置会启用本地用户认证,并且将用户限制在各自的家目录中。

4. 指定用户的根目录:

   - 在 vsftpd 中,可以设置 chroot 环境,这将限制用户在他们的家目录中活动。如果还未配置 chroot_local_user,可以添加或修改以下配置:

     user_sub_token=$USER
     local_root=/home/ftp/$USER

这样设置后,`$USER` 将会被替换为登录的用户名,从而将该用户限制在 /home/ftp/<用户名> 目录中。

5. 重启 vsftpd 服务:

   - 保存更改并退出编辑器,重启 vsftpd 以应用更改。

sudo systemctl restart vsftpd

6. 设置防火墙规则:

   - 如果使用防火墙,确保开放 21 端口以允许 FTP 流量。

sudo ufw allow 21/tcp

在这些设置之后,应该能够使用刚刚创建的 ftpusername 和对应的密码通过 FTP 客户端登录,并且用户将被限制在指定的根目录内。

四、虚拟用户登录【linux】Debian10.0配置vsftpd_第3张图片

在 Debian 中使用 vsftpd (Very Secure FTP Daemon) 还可以配置使其允许虚拟用户登录,这些虚拟用户并不是系统用户。要做到这一点,可以使用 PAM (Pluggable Authentication Modules) 来进行认证,并结合使用如 db4-utils 或者 libpam-pwdfile 等工具来管理虚拟用户的账户信息。

下面是使用 libpam-pwdfile 模块设置虚拟用户的基本步骤:

1. 安装 libpam-pwdfile:

   sudo apt-get update
   sudo apt-get install libpam-pwdfile

2. 配置 vsftpd 开启虚拟用户模式:

   编辑配置文件 /etc/vsftpd.conf,在文件中添加或修改以下选项:

   anonymous_enable=NO
   local_enable=YES
   write_enable=YES
   local_umask=022
   nopriv_user=vsftpd
   virtual_use_local_privs=YES
   guest_enable=YES
   user_sub_token=$USER
   local_root=/home/vsftpd/$USER
   chroot_local_user=YES
   hide_ids=YES
   guest_username=vsftpd
   pam_service_name=vsftpd

   这个配置将会启用虚拟用户模式,并且虚拟用户将会被映射到本地用户 vsftpd。此外,还将设置每个虚拟用户的家目录为 /home/vsftpd/$USER,其中 $USER 会被替换为虚拟用户名。

3. 配置 PAM 以使用 pwdfile:

   创建 PAM 配置文件 /etc/pam.d/vsftpd,里面包含如下内容以使用 libpam-pwdfile 进行用户验证:

   auth    required    pam_pwdfile.so pwdfile /etc/vsftpd/ftpd.passwd
   account required    pam_permit.so

   这里的 /etc/vsftpd/ftpd.passwd 是用来存储虚拟用户信息的文件。

4. 创建虚拟用户和密码文件:

   创建上述文件并添加用户,并且使用 htpasswd 命令(通常包含于 apache2-utils 包)来创建和管理密码文件。例如,创建一个名为 user1 的虚拟用户:

sudo htpasswd -cd /etc/vsftpd/ftpd.passwd user1

   -c 选项用于创建文件,如文件已存在请不要使用此选项,因为它会导致文件被覆盖。 -d 选项用于使用 crypt() 加密密码。

5. 创建映射本地用户与用户家目录:

   创建映射到虚拟用户的本地用户(如果尚未创建):

sudo useradd --home /home/vsftpd --gid nogroup -m --shell /bin/false vsftpd

   并为每个虚拟用户创建家目录:

   sudo mkdir /home/vsftpd/user1
   sudo chown vsftpd:nogroup /home/vsftpd/user1

6. 重启 vsftpd:

sudo systemctl restart vsftpd

现在,虚拟用户 user1 此时应该可以使用之前设置的密码通过 FTP 连接到服务器,而且没有一个对应的系统用户与其相关联。需要注意的是,此种方式并不是最安全的方式,且管理多个虚拟用户时会有些繁琐。在使用虚拟用户时,确保使用 SSL/TLS 等方式保护传输的数据,防止凭证泄露。

五、图形界面ftp服务器

在 Debian 10 (Buster) 上,默认并没有带有图形用户界面(GUI)的 FTP 服务器,因为大多数 FTP 服务器都是以命令行界面 (CLI) 形式运行的守护进程(例如 vsftpd, proftpd, pure-ftpd 等)。然而,可以使用一些具有图形界面的工具来管理和配置你的 FTP 服务器。以下是一些可选方案:

1. GAdmin-ProFTPD:

   GAdmin-ProFTPD 是一个基于 GTK+ 的图形界面,用于管理 ProFTPD 服务器。尽管它的更新可能不太频繁,但它可能在 Debian 10 的仓库中可用。可以通过执行以下命令尝试安装它:

   sudo apt update
   sudo apt install gadmin-proftpd

   安装完成后,可以从应用菜单中找到 GAdmin-ProFTPD 并运行它以配置 ProFTPD 服务器。

2. Webmin:

   Webmin 是一个基于 web 的系统管理界面,它允许通过浏览器管理服务器。Webmin 支持许多服务的管理,其中包括 ProFTPD 和 vsftpd。通过使用 Webmin,可以以图形方式配置 FTP 服务器而无需直接编辑配置文件。

   要在 Debian 10 上安装 Webmin,可能需要下载 Webmin 的 .deb 包或者添加 Webmin 的官方仓库到系统中。可以在 [Webmin 的官方网站](https://www.webmin.com/deb.html)上找到更多安装说明。

3. FileZilla:

   虽然 FileZilla 是一款流行的 FTP 客户端软件,但它也可以用来管理 FTP 服务器,尽管它不提供 FTP 服务本身。可以使用 FileZilla 连接到任何 FTP 服务器,并获取一个友好的界面来上传、下载和管理文件。可以通过以下命令在 Debian 10 上安装 FileZilla 客户端:

   sudo apt update
   sudo apt install filezilla

如果重点是在图形界面下轻松管理 FTP 服务,推荐尝试 Webmin,因为它集成了丰富的功能同时又比较容易安装和使用。对于只需偶尔手动管理文件的情况,标准的 FileZilla 客户端就足够用了。

六、相关链接

ubuntu16启动vsftpd服务_ubuntu16配置vsftpd-CSDN博客

你可能感兴趣的:(linux,网络,linux,服务器,运维)