在Debian系统上安全配置SSH服务是确保系统安全性的重要步骤。以下是一些关键的安全配置措施:
sudo apt-get update
sudo apt-get install openssh-server
sudo systemctl start ssh
sudo systemctl enable ssh
编辑/etc/ssh/sshd_config文件,进行以下配置:
Port 2222
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
AllowUsers user1 user2
重启SSH服务使配置生效:
sudo systemctl restart ssh
ssh-keygen -t rsa -b 4096
ssh-copy-id user@remote_server
或手动复制:
cat ~/.ssh/id_rsa.pub | ssh user@remote_server 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys'
sudo ufw allow 2222/tcp
sudo ufw enable
或配置Firewalld:
sudo firewall-cmd --permanent --add-port=2222/tcp
sudo firewall-cmd --reload
/etc/ssh/sshd_config中设置:PermitEmptyPasswords no
Logwatch或Fail2ban自动监控并报告系统活动。保持系统最新状态,安装所有可用的安全更新:
sudo apt update && sudo apt upgrade
通过上述步骤,可以显著提高Debian系统上SSH服务的安全性。建议定期审查和更新安全策略,以应对新的安全威胁。