Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

CentOS vsftpd 安裝配置全攻略:匿名/本地/虛擬用戶、PAM 認證、SELinux、防火牆、HTTP 下載整合

編輯:Linux 教學

1. 安裝與基礎服務管理

yum -y install vsftpd
touch /var/log/vsftpd.log
chkconfig --level 2345 vsftpd on
service vsftpd start

2. 核心配置 (/etc/vsftpd/vsftpd.conf)

anonymous_enable=NO          # 禁止匿名
local_enable=YES             # 允許本地用戶
chroot_list_enable=YES       # 限制用戶無法離開家目錄
xferlog_file=/var/log/vsftpd.log
ascii_upload_enable=YES
ascii_download_enable=YES
pam_service_name=vsftpd

3. 虛擬用戶支援 (需額外添加)

guest_enable=YES
guest_username=ftp
user_config_dir=/etc/vsftpd/vuser_conf

建立 /etc/vsftpd/chroot_list 並加入 ftp 用戶。

4. PAM 認證配置 (Berkeley DB)

yum install db4 db4-utils
# 建立用戶密碼文本 /etc/vsftpd/vuser_passwd.txt (奇行用戶名、偶行密碼)
db_load -T -t hash -f /etc/vsftpd/vuser_passwd.txt /etc/vsftpd/vuser_passwd.db
# 編輯 /etc/pam.d/vsftpd 全註釋,加入:
auth required pam_userdb.so db=/etc/vsftpd/vuser_passwd
account required pam_userdb.so db=/etc/vsftpd/vuser_passwd

5. 虛擬用戶個別配置

mkdir /etc/vsftpd/vuser_conf
vi /etc/vsftpd/vuser_conf/ftpuser1
local_root=/opt/var/ftp1
write_enable=YES
anon_umask=022
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES

6. 目錄建立與權限

mkdir /opt/var/ftp/ftpuser1
chmod 777 /opt/var/ftp/ftpuser1
service vsftpd restart

7. 常見問題排查

  • 553 Could not create file:setsebool -P ftpd_disable_trans 1 && service vsftpd restart (SELinux)
  • 500 OOPS: bad bool value:配置檔行尾有多餘空格,逐行檢查。
  • 虛擬用戶上傳檔案權限 600 無法下載:設定 anon_umask=022 或 000。

8. 系統用戶快速添加 (非虛擬用戶)

adduser -d /opt/dongge -g ftp -s /sbin/nologin dongge
passwd dongge
chown -R dongge:ftp /opt/dongge
mount --bind /opt/dongge /var/ftp/dongge

9. 整合 HTTP 下載

在 httpd.conf 添加 Alias /fileshare "/var/ftp/ftpuser1" 並授權目錄,重啟 httpd 即可用 https://IP/fileshare 下載。

Copyright © Windows教程網 All Rights Reserved