维护服务器安全需要从 系统加固、访问控制、监控响应 等多方面入手。以下是提升服务器安全性的 20个实用技巧,涵盖主流 Linux/Windows 系统场景:
一、基础加固措施
1. 最小化安装与更新
卸载无用软件:# Linux(Debian/Ubuntu)sudo apt purge telnet ftp rsh* yp-tools
# Windows
Get-WindowsFeature | Where InstallState -eq Installed | Uninstall-WindowsFeature
· 自动更新:
# Linux
sudo apt install unattended-upgrades && sudo dpkg-reconfigure -plow unattended-upgrades
# Windows
gpedit.msc > 计算机配置 > 管理模板 > Windows组件 > Windows更新 > 配置自动更新
2. 禁用root/Administrator直接登录
Linux:
sudo passwd -l root # 锁定root
sudo nano /etc/ssh/sshd_config
PermitRootLogin no # 禁用SSH root登录
· Windows:
o 组策略 > 本地策略 > 安全选项 > "帐户:管理员帐户状态" → 禁用
3. 防火墙严格化
· Linux(UFW/iptables):
· sudo ufw default deny incomingsudo ufw allow from 你的IP to any port 22sudo ufw enable
Windows:
powershell
·
New-NetFirewallRule -DisplayName "Block All" -Direction Inbound -Action Block
New-NetFirewallRule -DisplayName "Allow RDP" -RemoteAddress 你的IP -LocalPort 3389 -Protocol TCP -Action Allow
二、访问控制进阶
4. SSH安全强化
sudo nano /etc/ssh/sshd_config
Port 2222 # 修改默认端口
PermitEmptyPasswords no
MaxAuthTries 3 # 最大尝试次数
LoginGraceTime 1m # 登录超时
AllowUsers your_username # 仅允许特定用户
重启服务:
sudo systemctl restart sshd
5. 密钥认证替代密码
# 本地生成密钥
ssh-keygen -t ed25519 -C "server_access"
ssh-copy-id -p 2222 user@server_ip
# 强制禁用密码登录sudo sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
6. 双因素认证(2FA)
Linux(Google Authenticator):
sudo apt install libpam-google-authenticator
· google-authenticator
· Windows:使用 Microsoft Authenticator 或 Duo Security。
三、服务与权限管控
7. 限制sudo权限
sudo visudo# 仅允许用户执行特定命令
your_user ALL=(ALL) /usr/bin/apt, /usr/bin/systemctl
8. 文件权限最小化
# 关键目录权限sudo chmod 750 /etc /var/logsudo chown root:root /etc/shadowsudo chmod 600 /etc/shadow
9. 禁用危险服务
Linux:
sudo systemctl disable avahi-daemon cups bluetooth
· Windows:
powershell
Stop-Service -Name "Telnet" -ForceSet-Service -Name "Telnet" -StartupType Disabled
四、入侵检测与监控
10. 日志集中管理
· Linux(rsyslog):
sudo apt install rsyslogsudo nano /etc/rsyslog.conf
*.emerg @192.168.1.100:514 # 转发到日志服务器
· Windows(Event Forwarding):
组策略 > 计算机配置 > 管理模板 > Windows组件 > 事件转发。
11. 文件完整性监控(AIDE/Tripwire)
sudo apt install aidesudo aideinitsudo aide --check
12. 入侵检测工具
· Fail2Ban(防暴力破解):
sudo apt install fail2bansudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
· Windows:使用 Windows Defender ATP 或 OSSEC。
五、数据安全与备份
13. 全盘加密(LUKS/BitLocker)
Linux:
· sudo cryptsetup luksFormat /dev/sda2sudo cryptsetup open /dev/sda2 encrypted_volume
· Windows:
控制面板 > BitLocker驱动器加密。
14. 自动化备份策略
· Linux(rsync + cron):
sudo crontab -e
0 3 * * * rsync -avz /data backup_user@backup_server:/backups
· Windows:
任务计划程序 + Robocopy 或 Veeam。
六、网络层防护
15. TCP/IP栈加固
# Linux(防SYN洪水)echo "net.ipv4.tcp_syncookies = 1" | sudo tee -a /etc/sysctl.confsudo sysctl -p
16. 端口隐藏(端口敲门)
sudo apt install knockdsudo nano /etc/knockd.conf
[options]
sequence = 7000,8000,9000
seq_timeout = 10
command = /sbin/iptables -A INPUT -s %IP% -p tcp --dport 22 -j ACCEPT
七、容器与虚拟化安全
17. Docker安全配置
# 禁止容器特权模式
docker run --cap-drop=ALL --security-opt=no-new-privileges nginx
# 启用用户命名空间
sudo nano /etc/docker/daemon.json
{ "userns-remap": "default" }
18. 虚拟机隔离
· KVM:启用 sVirt 和 SELinux。
· Hyper-V:开启 Shielded VM。
八、应急响应
19. 恶意进程排查
# Linux(检查异常进程)
ps auxf | grep -i "backdoor"
lsof -i :6666
# Windows
tasklist /svc | findstr "可疑进程名"
netstat -ano | findstr "ESTABLISHED"
20. 快速隔离攻击源
sudo iptables -A INPUT -s 攻击IP -j DROPsudo fail2ban-client set sshd banip 攻击IP
安全工具推荐
用途 | Linux工具 | Windows工具 |
防火墙 | UFW/iptables | Windows Defender FW |
入侵检测 | Fail2Ban/OSSEC | Windows Defender ATP |
日志分析 | ELK Stack | Splunk/Sentinel |
漏洞扫描 | OpenVAS | Nessus |
总结 Checklist
1. 禁用root/Administrator直接登录
2. 强制密钥认证 + 2FA
3. 防火墙仅开放必要端口
4. 关键目录权限设置为750
5. 安装Fail2Ban/AIDE
6. 每周审核日志/备份
7. 所有服务使用最新稳定版
通过以上措施,可显著降低服务器被入侵风险。安全是一个持续过程,需定期审计和更新策略!
windows网络安全调整,windows网络安全调试,linux系统网络安全调试,linux系统网络安全调整,windows服务器网络安全策略,windows网络安全部署,linux服务器安全策略,linux服务器网络安全部署
目前有0 条留言