记在腾讯云买了个云服务器之后做的安全优化。(ps:系统是 centos 7)

新增一个普通帐号

新建一个普通账号并设置密码。

adduser xxx
passwd xxx

禁止 root 使用 ssh 登入

在 /etc/ssh/sshd_config 寻找 #PermitRootLogin yes改为 PermitRootLogin no

然后重启systemctl restart sshd

完成后不要登出系统,使用另一个视窗尝试登入 root 和普通帐号,测试无误才行。

然后吧 sudo 权限给你新建的用户。

在文件 /etc/sudoer 里找到 root ALL=(ALL) ALL 在下一行添加你想要的用户 xxx ALL=(ALL) ALL

修改 ssh 端口

vim /etc/ssh/sshd_config

#Port 22 改为你想要的端口

启动防火墙

systemctl start firewalld

这是还有配置你修改的 ssh 端口

cp /usr/lib/firewalld/services/ssh.xml /etc/firewalld/services/
vi /etc/firewalld/services/ssh.xml

<port protocol="tcp" port="22"/> 改为 <port protocol="tcp" port="xxxxx"/>

重新加载 firewalld

firewall-cmd --reload

firewall-cmd --list-all 查看防火墙现在开启了哪些服务和端口,如果安装了 nginx 可以如下添加设置,开放 http 端口

firewall-cmd --permanent --zone=public --add-service=http 
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

启用公钥验证登入 ssh

更新

保持你用的系统软件更新来防止安全漏洞

yum -y update