ubuntu

Ubuntu FTP服务器如何配置被动模式

小樊
43
2025-07-18 11:42:16
栏目: 云计算

在Ubuntu上配置FTP服务器以支持被动模式,通常需要使用vsftpd(Very Secure FTP Daemon)。以下是详细的步骤:

1. 安装vsftpd

首先,确保你已经安装了vsftpd。如果没有安装,可以使用以下命令进行安装:

sudo apt update
sudo apt install vsftpd

2. 配置vsftpd

编辑vsftpd的配置文件 /etc/vsftpd.conf

sudo nano /etc/vsftpd.conf

在配置文件中,确保以下设置:

listen=YES
listen_ipv6=NO
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
chroot_local_user=YES
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

3. 配置被动模式

/etc/vsftpd.conf 文件中,添加或修改以下行以启用被动模式:

pasv_enable=YES
pasv_min_port=1024
pasv_max_port=1048

4. 配置防火墙

如果你使用的是UFW(Uncomplicated Firewall),确保开放被动模式的端口范围:

sudo ufw allow 1024:1048/tcp

5. 重启vsftpd服务

保存并关闭配置文件后,重启vsftpd服务以应用更改:

sudo systemctl restart vsftpd

6. 测试FTP连接

使用FTP客户端连接到你的服务器,确保被动模式正常工作。大多数FTP客户端默认使用被动模式,但你可以手动选择被动模式以确保连接成功。

7. 可选:配置PAM

如果你希望使用PAM(Pluggable Authentication Modules)进行用户认证,确保 /etc/pam.d/vsftpd 文件中有以下行:

auth required pam_listfile.so item=user sense=allow file=/etc/vsftpd.user_list onerr=succeed

并在 /etc/vsftpd.user_list 文件中添加允许访问FTP的用户。

通过以上步骤,你应该能够在Ubuntu上成功配置vsftpd以支持被动模式的FTP连接。

0
看了该问题的人还看了