在Ubuntu上實現FTP的SSL加密,通常有兩種方法:使用FTPS(FTP over SSL)或SFTP(SSH File Transfer Protocol)。以下是這兩種方法的詳細步驟:
安裝vsftpd和SSL證書
sudo apt update
sudo apt install vsftpd openssl
生成SSL證書
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/vsftpd.pem -out /etc/ssl/certs/vsftpd.pem
配置vsftpd
編輯/etc/vsftpd.conf
文件,添加或修改以下配置:
listen=YES
listen_ipv6=NO
anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
allow_writeable_chroot=YES
ssl_enable=YES
force_local_data_ssl=YES
force_local_logins_ssl=YES
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
rsa_cert_file=/etc/ssl/certs/vsftpd.pem
rsa_private_key_file=/etc/ssl/private/vsftpd.pem
重啟vsftpd服務
sudo systemctl restart vsftpd
安裝OpenSSH服務器
sudo apt update
sudo apt install openssh-server
配置SSH服務器
編輯/etc/ssh/sshd_config
文件,確保以下配置存在并正確:
Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
UsePrivilegeSeparation sandbox
KeyRegenerationInterval 3600
ServerKeyBits 1024
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
PermitRootLogin no
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
PasswordAuthentication yes
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL
Subsystem sftp /usr/lib/openssh/sftp-server
重啟SSH服務
sudo systemctl restart sshd
配置防火墻 如果你使用的是UFW防火墻,確保允許SSH連接:
sudo ufw allow 22/tcp
sudo ufw reload
通過以上步驟,你可以在Ubuntu上實現FTP的SSL加密,確保數據傳輸的安全性。