Debian SFTP加密传输配置指南
一 概念澄清与准备
sudo apt update && sudo apt install openssh-serversudo ufw allow 22/tcp && sudo ufw reload二 基础安全配置步骤
sudo nano /etc/ssh/sshd_config,建议进行以下设置:
PubkeyAuthentication yesAuthorizedKeysFile .ssh/authorized_keysCiphers aes128-ctr,aes192-ctr,aes256-ctrMACs hmac-sha2-256,hmac-sha2-512KexAlgorithms diffie-hellman-group-exchange-sha256~/.ssh/authorized_keys,并确保权限正确(如 .ssh 目录权限为 700、authorized_keys 为 600)。sudo systemctl restart sshd。sftp -o Port=22 username@your_server_ip,确认可正常登录且传输加密生效。三 加固与隔离 SFTP 用户
sudo groupadd sftp_userssudo useradd -m -G sftp_users usernamesudo chpasswd/etc/ssh/sshd_config 末尾添加Match Group sftp_users
X11Forwarding no
AllowTcpForwarding no
ChrootDirectory %h
ForceCommand internal-sftp
说明:%h 表示用户家目录,用户将被限制在此目录内;internal-sftp 为内置 SFTP,更安全且便于 chroot。sudo systemctl restart sshd。四 主机密钥与证书说明
sudo apt update && sudo apt install vsftpd opensslsudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/vsftpd.pem -out /etc/ssl/certs/vsftpd.pemssl_enable=YESforce_local_data_ssl=YESforce_local_logins_ssl=YESrsa_cert_file=/etc/ssl/certs/vsftpd.pemrsa_private_key_file=/etc/ssl/private/vsftpd.pemsudo ufw allow 21/tcp && sudo ufw allow 990/tcp && sudo systemctl restart vsftpd