【51CTO.com 快译】任何一套关键性系统都需要高度重视服务器安全性,特别是在公有云环境当中。在今天的文章中,我们将专注于基本原理与一般性最佳实践层面对此加以解读。

我在操作系统配置完成之后始终坚持执行的安全改进举措。
让我们以Ubuntu 16.04为例: 1.保持内核随时更新。环境虽然不应该盲目更新,不过在刚刚安装完成的服务器当中,版本更新一般都能够带来更理想的安全成效。
其中一项常规建议是禁用各项未使用采取行动。不过我个人非常信任发行版供应商。一般来讲,我认为他们给出的默认安装及启用选项还是相当可靠的。
apt-get-yupdate 2. 重置Root密码。我们有时候需要在ssh无法起效的情况下访问各虚拟机的网络控制台,这类状况包括iptables规则将我们屏蔽、操作系统内核出现问题或者虚拟机神秘重启等等。
root_pwd="DevOpsDennyChangeMe1" echo"root:$root_pwd"|chpasswd 3. 强化SSHD。在keyfile当中仅允许ssh访问,这意味着黑客无法轻松猜到我们的密码内容。使用除端口22之外的其它ssh监听端口,这能够有效避免恶意ssh登录尝试。
#Disablesshbypassword sed-i's/^#PasswordAuthenticationyes/PasswordAuthenticationno/g'\ /etc/ssh/sshd_config sed-i's/PasswordAuthenticationyes/PasswordAuthenticationno/g'\ /etc/ssh/sshd_config grepPasswordAuthentication/etc/ssh/sshd_config #Useanothersshport sshd_port="2702" sed-i"s/^Port22/Port$sshd_port/g"/etc/ssh/sshd_config grep"^Port"/etc/ssh/sshd_config #Restartsshdtotakeeffect servicesshrestart 4.利用防火墙限制恶意访问。这可能是大家应当采取的最为重要的安全改进举措了。
#Disablesshbypassword sed-i's/^#PasswordAuthenticationyes/PasswordAuthenticationno/g'\ /etc/ssh/sshd_config sed-i's/PasswordAuthenticationyes/PasswordAuthenticationno/g'\ /etc/ssh/sshd_config grepPasswordAuthentication/etc/ssh/sshd_config #Useanothersshport sshd_port="2702" sed-i"s/^Port22/Port$sshd_port/g"/etc/ssh/sshd_config grep"^Port"/etc/ssh/sshd_config #Restartsshdtotakeeffect servicesshrestart #Haveacleanstartwithiptables iptables-F;iptables-X echo'y'|ufwreset echo'y'|ufwenable ufwdefaultdenyincoming ufwdefaultdenyforward #Allowtrafficofsafeports ufwallow22,80,443/tcp #Allowtrafficfromcertainport ufwallow2702/tcp #Allowtrafficfromtrustedip ufwallowfrom52.74.151.55 5.向命令历史中添加时间戳。通过这种方式,我们能够查看哪些命令曾在何时得以执行。
echoexportHISTTIMEFORMAT=\"%h%d%H:%M:%S\">>/root/.bashrc 6.生成SSH密钥对。永远、永远不要在不同服务器之间共享同一ssh密钥对!
execssh-agentbash #Generalnewkeypair ssh-keygen #Loadkeypair ssh-add 7.高度关注var/log。使用logwatch以自动执行检查与分析任务。这是一套实用的解析型perl脚本,能够分析系统日志活动并生成报告。其中需要关注的重点日志文件包括:
◆/var/log/kern.log
◆/var/log/syslog
◆/var/log/ufw.log
◆/var/log/auth.log
◆/var/log/dpkg.log
◆/var/log/aptitude
◆/var/log/boot.log
◆/var/log/cron.log
◆/var/log/mailog
execssh-agentbash #Generalnewkeypair ssh-keygen #Loadkeypair ssh-add apt-getinstall-ylogwatch #Fullcheck.Takesseveralminutes logwatch--rangeALL #OnlychecklogofToday logwatch--rangeToday 8.运行第三方安全检查工具。并不是每位用户都具备强大的安全知识储备。因此最好选择可靠且多样化的工具方案。Lynis易于使用且功能可靠――其仅作为单一bash文件存在。
apt-getinstall-ylynis #Runlynistochecksecurityissues lynis-c 9.适当备份无法恢复的数据。永远要筹备一套B计划。作为最后补救手段,其应该能够将系统快速恢复至新服务器之上。
原文标题:9 Useful Tips For linux Server Security 作者:Denny Zhang
【51CTO译稿,合作站点转载请注明原文译者和出处为51CTO.com】