确保Ubuntu SSH的安全性是非常重要的,因为SSH是远程访问服务器的主要方式之一。以下是一些提高Ubuntu SSH安全性的建议:
/etc/ssh/sshd_config,添加或修改以下行:Port 2222
sudo systemctl restart sshd
/etc/ssh/sshd_config 中设置:PermitRootLogin no
sudo systemctl restart sshd
ssh-keygen -t rsa
~/.ssh/authorized_keys 文件中。ssh-keygen -t rsa -b 4096
ssh-copy-id user@server_ip
sshd_config 文件中启用了公钥认证:PubkeyAuthentication yes
sudo ufw allow 2222/tcp
sudo ufw enable
sudo apt-get install fail2ban
/etc/fail2ban/jail.local 文件,在 [ssh] 部分进行如下配置:enabled = true
port = 2222
filter = ssh
logpath = /var/log/auth.log
maxretry = 3
bantime = 600
sudo systemctl restart fail2ban
sudo apt update
sudo apt upgrade