配置Ubuntu服務器以確保其安全性是一個涉及多個方面的過程。以下是一些關鍵的安全配置步驟和最佳實踐:
sudo apt update
sudo apt upgrade -y
sudo apt-get install unattended-upgrades
sudo apt install ufw
sudo ufw enable
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
ssh-copy-id user@server_ip
sudo nano /etc/ssh/sshd_config
# 修改以下行
PasswordAuthentication no
PermitRootLogin no
sudo systemctl restart sshd
sudo chmod 700 /home/user
sudo chown user:user /home/user
sudo apt install fail2ban
sudo cp /etc/fail2ban/jail.local /etc/fail2ban/jail.local.bak
sudo systemctl start fail2ban
sudo systemctl enable fail2ban
sudo apt install rsyslog
sudo nano /etc/rsyslog.conf
sudo apt install borgbackup
borg init --encryption=repokey /backup
borg create /backup::"{now}" /path/to/data
sudo aa-status
通過上述步驟,可以顯著提高Ubuntu服務器的安全性。請定期檢查和更新系統,以確保您的數據安全。