前言
最近在阿里云上买了一台 2C2G 的轻量应用服务器,系统选了 Rocky Linux 8.x。这篇文章记录从零开始的初始化与安全加固过程。
SSH 密钥登录
首先在本地生成密钥对:
ssh-keygen -t ed25519 -C "hengjiu@server"
然后将公钥复制到服务器:
ssh-copy-id -i ~/.ssh/id_ed25519.pub root@your-server-ip
最后在 /etc/ssh/sshd_config 中禁用密码登录:
PasswordAuthentication no PermitRootLogin prohibit-password
配置 firewalld
systemctl enable firewalld --now firewall-cmd --permanent --add-service=http firewall-cmd --permanent --add-service=https firewall-cmd --reload
启用 SELinux
检查 SELinux 状态:
getenforce
如果未启用,修改 /etc/selinux/config:
SELINUX=enforcing
总结
以上三步做完,服务器的基础安全就有了保障。之后就可以安心部署服务了。