在Ubuntu上使用FTPServer(通常是vsftpd)时,可以通过配置文件来限制用户的访问。以下是一些常见的方法:
首先,确保你已经安装了vsftpd:
sudo apt update
sudo apt install vsftpd
编辑vsftpd的配置文件:
sudo nano /etc/vsftpd.conf
你可以通过设置local_enable和write_enable来控制用户是否可以登录和写入:
local_enable=YES
write_enable=NO
你可以使用chroot来限制用户只能访问他们的主目录:
chroot_local_user=YES
allow_writeable_chroot=YES
如果你只想允许特定的用户登录,可以使用userlist_enable和userlist_file:
userlist_enable=YES
userlist_file=/etc/vsftpd.userlist
userlist_deny=NO
然后在/etc/vsftpd.userlist文件中添加允许的用户:
sudo nano /etc/vsftpd.userlist
添加用户名,每行一个。
为了使用FTPS,你需要配置SSL/TLS。首先生成证书和密钥:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/vsftpd.pem -out /etc/ssl/private/vsftpd.pem
编辑vsftpd配置文件以启用SSL/TLS:
sudo nano /etc/vsftpd.conf
添加或修改以下行:
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
rsa_cert_file=/etc/ssl/private/vsftpd.pem
rsa_private_key_file=/etc/ssl/private/vsftpd.pem
保存配置文件并重启vsftpd服务以应用更改:
sudo systemctl restart vsftpd
确保你的防火墙允许FTP和FTPS流量。例如,使用ufw:
sudo ufw allow 21/tcp
sudo ufw allow 990/tcp # FTPS control connection
sudo ufw allow 40000:50000/tcp # Passive mode ports
通过以上步骤,你可以有效地限制用户在Ubuntu上的FTPServer访问。