openEuler 搭建 vsftpd 服务器(FTP Over SSL、虚拟用户)

(首发地址:学习日记 https://www.learndiary.com/2024/09/openeuler-install-vsftpd/

本文简述如何在 openEuler 24.03 LTS 国产服务器操作系统上搭建 vsftpd 3.0.5 服务器,安全起见,设置了 FTP Over SSL 和虚拟用户。

其中,虚拟用户的方案主要基于 vsftpd 3.0.5 源码的 VIRTUAL_USERS 和 VIRTUAL_USERS_2 示例修改。另外,因为本文使用的系统和软件版本较新,相比一些老旧的系统如 CentOS 7,其中可能需要作出一些修改,我也会特别的指出。视频演示:【Linux 搭建 sftp 服务器详解】 https://www.bilibili.com/video/BV1uGpvewERK/

openEuler 搭建 vsftpd 服务器(FTP Over SSL、虚拟用户)

一、安装

sudo yum install vsftpd vsftpd-help
sudo systemctl enable vsftpd
sudo systemctl start vsftpd

二、创建虚拟用户

# 示例中使用 db_load,这里要用 gdbmtool 设置虚拟用户账户
# 参考链接:openEuler部署vsftpd的异常问题
# https://cloud.tencent.com/developer/article/2347573
sudo gdbmtool /etc/vsftpd/login.pag store ftp1 123456
sudo gdbmtool /etc/vsftpd/login.pag store ftp2 123456
sudo gdbmtool /etc/vsftpd/login.pag store ftp3 123456
# sudo gdbmtool /etc/vsftpd/login.pag delete ftp1
sudo gdbmtool /etc/vsftpd/login.pag list
sudo chmod 600 /etc/vsftpd/login.pag -v

三、创建使用虚拟用户数据库的 PAM 文件

sudo nano /etc/pam.d/vsftpd.virtual
# 内容如下:
#%PAM-1.0
auth       required     pam_userdb.so db=/etc/vsftpd/login
account    required     pam_userdb.so db=/etc/vsftpd/login
session    required     pam_loginuid.so

四、设置映射虚拟用户的实体用户及 ftp 文件目录

sudo useradd -d /home/ftpsite virtual
# 默认 ftp chroot 根目录不能可写
sudo chmod a-w /home/ftpsite -v
ls -ld /home/ftpsite
sudo mkdir /home/ftpsite/files -v
sudo chown virtual:virtual /home/ftpsite -Rv

五、创建 ssl 证书和密钥

# 参考链接 Configure Vsftpd With SSL/TLS On CentOS 7
# https://www.osradar.com/configure-vsftpd-with-ssl-tls-on-centos-7/
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/vsftpd/vsftpd.pem -out /etc/vsftpd/vsftpd.pem

六、设置防火墙

sudo firewall-cmd --permanent --add-port={10021,30000-30999}/tcp
sudo firewall-cmd --reload
sudo firewall-cmd --zone=public --list-all

七、创建 vsftpd.conf 主配置文件

sudo mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.orig -v
sudo nano /etc/vsftpd/vsftpd.conf
# 内容如下:
anonymous_enable=NO
# 本地或虚拟用户需要
local_enable=YES
# 是否可以写的总开头
write_enable=NO
# 是否可以上传
anon_upload_enable=NO
# 是否可以新建目录
anon_mkdir_write_enable=NO
# 是否可以修改删除原有文件
anon_other_write_enable=NO
chroot_local_user=YES

guest_enable=YES
guest_username=virtual

listen=YES
listen_port=10021

ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO

# 设置 SSL 加密算法,否则报错:"500 OOPS: SSL: could not set cipher list"(openEuler 24.03 LTS 需要)
# 参考链接 How do I configure vsftpd and openssl to avoid TLS unsupported protocol error with Sony Camera
# https://stackoverflow.com/questions/65316357/how-do-i-configure-vsftpd-and-openssl-to-avoid-tls-unsupported-protocol-error-wi
ssl_ciphers=HIGH:AES256-SHA:!aNULL

rsa_cert_file=/etc/vsftpd/vsftpd.pem
rsa_private_key_file=/etc/vsftpd/vsftpd.pem

pasv_min_port=30000
pasv_max_port=30999

# 账户登录 PAM 配置文件(openEuler 24.03 LTS 需要 gdbmtool 设置虚拟用户账户)
pam_service_name=vsftpd.virtual
# 用户级自定义配置文件夹
user_config_dir=/etc/vsftpd/vsftpd_user_conf

# 允许在 chroot 的根目录下可写,或者去掉 chroot 根目录的所有可写权限。否则不能登录。安全原因默认为 NO
# allow_writeable_chroot=YES

八、分别设置各虚拟用户的权限

sudo mkdir /etc/vsftpd/vsftpd_user_conf -v
# 用户 ftp1(仅下载)
sudo nano /etc/vsftpd/vsftpd_user_conf/ftp1
# 内容如下:
# 当设为YES时,文件夹和文件不能被所有用户读时,将不能下载文件或列出文件夹里面的内容。默认为 YES
anon_world_readable_only=NO

# 用户 ftp2(可上传下载)
sudo nano /etc/vsftpd/vsftpd_user_conf/ftp2
# 内容如下:
anon_world_readable_only=NO
write_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES

# 用户 ftp3(仅上传)
sudo nano /etc/vsftpd/vsftpd_user_conf/ftp3
# 内容如下:
anon_world_readable_only=NO
download_enable=NO
write_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES

# 配置文件编辑完成后,重启一下 vsftpd
sudo systemctl restart vsftpd

九、参考资料:

  1. vsftpd https://security.appspot.com/vsftpd.html
  2. vsftpd 3.0.5 示例
  3. man vsftpd.conf
  4. Ubuntu 社区帮助 wiki: vsftpd https://help.ubuntu.com/community/vsftpd
  5. How do I configure vsftpd and openssl to avoid TLS unsupported protocol error with Sony Camera [closed] https://stackoverflow.com/questions/65316357/how-do-i-configure-vsftpd-and-openssl-to-avoid-tls-unsupported-protocol-error-wi
  6. Configure Vsftpd With SSL/TLS On CentOS 7 https://www.osradar.com/configure-vsftpd-with-ssl-tls-on-centos-7/
  7. PowerScale OneFS: Error Received After Upgrade "500 OOPS: Vsftpd: Refuses to Run with Writable Root Inside Chroot" https://www.dell.com/support/kbdoc/en-us/000214872/500-oops-vsftpd-refusing-to-run-with-writable-root-inside-chroot
  8. openEuler部署vsftpd的异常问题 https://cloud.tencent.com/developer/article/2347573
  9. Setup vsftp with SELinux https://hostodo.com/legacy/portal/knowledgebase/25/Setup-vsftp-with-SELinux.html
相关推荐
小狮子安度因29 分钟前
边缘智能-大模型架构初探
linux·网络
晨春计33 分钟前
【git】
android·linux·git
Flying_Fish_roe1 小时前
linux-软件包管理-包管理工具(RedHat/CentOS 系)
linux·运维·centos
Splashtop高性能远程控制软件1 小时前
centos远程桌面连接windows
linux·windows·centos·远程控制·远程桌面
tang&1 小时前
【Linux】进程概念
linux
苏少朋1 小时前
Docker安装 ▎Docker详细讲解 ▎数据卷挂载 ▎Nginx安装理解
linux·nginx·docker·容器
Jerry 二河小鱼1 小时前
在Linux中安装FFmpeg
linux·运维·服务器·ffmpeg
Roc-xb2 小时前
如何在 CentOS 上安装和使用 Neofetch(图文教程)
linux·运维·centos
程序员大阳2 小时前
Linux(6)--CentOS目录
linux·centos·目录
小技与小术2 小时前
lvs命令介绍
linux·运维·服务器·lvs