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
相关推荐
眠修11 分钟前
Kuberrnetes 服务发布
linux·运维·服务器
即将头秃的程序媛3 小时前
centos 7.9安装tomcat,并实现开机自启
linux·运维·centos
fangeqin3 小时前
ubuntu源码安装python3.13遇到Could not build the ssl module!解决方法
linux·python·ubuntu·openssl
爱奥尼欧5 小时前
【Linux 系统】基础IO——Linux中对文件的理解
linux·服务器·microsoft
超喜欢下雨天5 小时前
服务器安装 ros2时遇到底层库依赖冲突的问题
linux·运维·服务器·ros2
tan77º6 小时前
【Linux网络编程】网络基础
linux·服务器·网络
笑衬人心。6 小时前
Ubuntu 22.04 + MySQL 8 无密码登录问题与 root 密码重置指南
linux·mysql·ubuntu
chanalbert8 小时前
CentOS系统新手指导手册
linux·运维·centos
星宸追风8 小时前
Ubuntu更换Home目录所在硬盘的过程
linux·运维·ubuntu
热爱生活的猴子9 小时前
Poetry 在 Linux 和 Windows 系统中的安装步骤
linux·运维·windows