在Ubuntu上设置FTP服务器时,确保其安全性是非常重要的。以下是一些防止非法登录的措施:
使用强密码:
限制FTP访问:
ufw(Uncomplicated Firewall)来配置防火墙规则。sudo ufw allow from <允许的IP地址> to any port 21
sudo ufw enable
使用SSL/TLS加密:
vsftpd-ssl包。sudo apt-get install vsftpd-ssl
编辑/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
使用SFTP代替FTP:
openssh-server来提供SFTP服务。sudo apt-get install openssh-server
SFTP默认监听端口22,可以通过配置sshd_config文件来更改端口。
限制用户权限:
chroot来限制用户的根目录。对于vsftpd,可以在/etc/vsftpd.conf文件中添加以下配置:
chroot_local_user=YES
allow_writeable_chroot=YES
监控和日志记录:
/etc/vsftpd.conf文件,确保以下配置项被启用:xferlog_enable=YES
xferlog_file=/var/log/vsftpd.log
connect_from_port_20=YES
定期更新和打补丁:
apt-get update和apt-get upgrade命令来更新系统。通过以上措施,可以大大提高Ubuntu上FTP服务器的安全性,防止非法登录和其他安全威胁。