服务器的安全问题并不是很复杂,采取下面的原则阻止最常见的攻击行为。
经验丰富的管理员都知道,随着服务器数量和用户的增加,用户管理成本会原来越大
以下命名以ubuntu为例,其它版本linux会有所不同。
passwd
apt-get update
apt-get upgrade
apt-get install fail2ban
useradd deploy
mkdir /home/deploy
mkdir /home/deploy/.ssh
chmod 700 /home/deploy/.ssh
vim /home/deploy/.ssh/authorized_keys
chmod 400 /home/deploy/.ssh/authorized_keys
chown deploy:deploy /home/deploy -R
passwd deploy
visudo
#添加如下
root ALL=(ALL) ALL
deploy ALL=(ALL) ALL
vim /etc/ssh/sshd_config
#添加如下行
PermitRootLogin no
PasswordAuthentication no
AllowUsers deploy@(your-ip) deploy@(another-ip-if-any)
#修改完成后重启
service ssh restart
ufw allow from {your-ip} to any port 22
ufw allow 80
ufw allow 443
ufw enable
apt-get install unattended-upgrades
vim /etc/apt/apt.conf.d/10periodic
#更新如下内容
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Unattended-Upgrade "1";
Unattended-Upgrade::Allowed-Origins {
"Ubuntu lucid-security";
// "Ubuntu lucid-updates";
};
apt-get install logwatch
vim /etc/cron.daily/00logwatch
#添加如下
/usr/sbin/logwatch --output mail --mailto test@gmail.com --detail high