保障Ubuntu SSH的安全性是非常重要的,因為SSH(Secure Shell)是遠程訪問和管理服務器的主要方式之一。以下是一些提高Ubuntu SSH安全性的最佳實踐:
ssh-keygen
命令生成公鑰和私鑰。ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
ssh-copy-id
命令將公鑰復制到服務器的~/.ssh/authorized_keys
文件中。ssh-copy-id user@server_ip
/etc/ssh/sshd_config
文件,找到并修改以下行:PasswordAuthentication no
sudo systemctl restart sshd
sudo ufw allow 22/tcp
sudo ufw enable
/etc/ssh/sshd_config
文件,找到并修改以下行:Port 2222
sudo systemctl restart sshd
/etc/ssh/sshd_config
文件中,確保以下行未被注釋:PubkeyAuthentication yes
PasswordAuthentication yes
sudo apt-get install fail2ban
sudo apt-get update && sudo apt-get upgrade
/var/log/auth.log
)以發現任何可疑活動。sudo tail -f /var/log/auth.log
通過遵循這些最佳實踐,可以顯著提高Ubuntu SSH的安全性,減少潛在的安全風險。