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
相关推荐
A小辣椒2 天前
TShark:Wireshark CLI 功能
linux
A小辣椒3 天前
TShark:基础知识
linux
AlfredZhao3 天前
OCI 明明分配了 200G 系统盘,为什么 df 只看到 30G?
linux·oci
AlfredZhao3 天前
vi 删除指定范围的行,不用再反复按 dd
linux·vi
用户9718356334664 天前
银河麒麟 KY10 申威(SW64) 安装 nginx-1.16.1-2.p01.ky10.sw_64.rpm 详细步骤
linux
猪脚踏浪4 天前
linux 拷贝文件或目录到指定的位置
linux
摇滚侠4 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
bush44 天前
嵌入式linux学习记录十四、术语
linux·嵌入式
载数而行5204 天前
Linux 11 动态监控指令top
linux
不会C语言的男孩4 天前
Linux 系统编程 · 第 8 章:进程基础
linux·c语言