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

Vsftpd 在 SUSE Linux 上的安裝、配置與防火牆開放實戰

編輯:Linux 教學

前言

Vsftpd (Very Secure FTP Daemon) 是 Linux 常用的 FTP 伺服器軟體,以安全、輕量著稱。本文記錄在 SUSE Linux (openSUSE/SLES) 上透過 YaST 安裝、啟動服務、切換至本地使用者模式、開放防火牆端口的完整流程,並解決「僅允許匿名登入」與「外部無法連線」兩大常見問題。

一、安裝 Vsftpd

使用 YaST 圖形介面

  1. 開啟 YaST → 軟體 → 軟體管理
  2. 過濾器選 套件群組 → 生產力 → 網路 → FTP → 伺服器
  3. 勾選 vsftpd,點擊 接受
  4. 提示插入安裝媒體(光碟/ISO),完成安裝

命令列安裝(備選)

zypper install vsftpd

二、啟動服務

Vsftpd 預設以獨立模式運行(非 xinetd 管理)。

  1. YaST → 系統 → 系統服務 (Runlevel)
  2. 選擇 vsftpd,點擊 啟用 → 完成
  3. 若啟動失敗,檢查相依服務 syslog 是否已啟動,必要時重啟 xinetd 再試

命令列操作

systemctl enable vsftpd
systemctl start vsftpd
systemctl status vsftpd

三、常見問題與解決

問題 1:僅允許匿名登入,本地使用者無法登入

現象:輸入本地帳號密碼提示 530 This FTP server is anonymous only

原因:預設配置 anonymous_enable=YES、local_enable=NO

解決:編輯 /etc/vsftpd.conf

# 允許本地使用者登入
local_enable=YES
# 可選:禁止匿名登入
anonymous_enable=NO
# 指定監聽端口(預設 21)
listen_port=21
# 寫入權限
write_enable=YES
# 限制使用者在家目錄(安全建議)
chroot_local_user=YES
allow_writeable_chroot=YES

重啟服務:systemctl restart vsftpd

問題 2:本機測試正常,但其他機器無法連線

現象:Connection closed by remote host 或 Connection timed out

原因:SUSE 防火牆 (SuSEfirewall2 / firewalld) 預設封鎖 FTP 端口 (20, 21)

解決:

方案 A:YaST 防火牆模組

  1. YaST → 安全性與使用者 → 防火牆
  2. 左側選 允許的服務,服務列表中無 FTP 選項
  3. 點擊 進階 → TCP 埠號 輸入 20 21(空格分隔)
  4. 下一步 → 接受

方案 B:firewalld 命令列 (SLES 15 / openSUSE 15+)

firewall-cmd --permanent --add-service=ftp
firewall-cmd --permanent --add-port=20/tcp
firewall-cmd --reload

方案 C:SuSEfirewall2 (舊版)

# 編輯 /etc/sysconfig/SuSEfirewall2
FW_SERVICES_EXT_TCP="21 20"
# 重啟防火牆
systemctl restart SuSEfirewall2

四、驗證測試

# 本機測試
ftp localhost
# 遠端測試
ftp 192.168.1.8
# 使用本地帳號登入,確認可上傳/下載檔案

五、進階配置提示

  • 被動模式端口範圍:pasv_min_port=40000、pasv_max_port=40100,並同步開放防火牆
  • SSL/TLS 加密:啟用 ssl_enable=YES,指定憑證檔案,強制加密傳輸
  • 虛擬使用者:配合 pam_userdb 或 guest_enable=YES 實現非系統帳號 FTP 存取
  • 日誌與審計:xferlog_enable=YES、log_ftp_protocol=YES

總結

Vsftpd 在 SUSE 上部署的核心步驟:YaST 安裝 → 啟用獨立服務 → 修改 vsftpd.conf 允許本地使用者 → 開放防火牆 20/21 端口。此流程在其他發行版 (CentOS、Ubuntu、Debian) 亦同理可循,僅套件管理器與防火牆工具不同。

Copyright © Windows教程網 All Rights Reserved