Linux 服务器安全加固 10 步清单:从 SSH 到防火墙

< p > 一 台 新 买 的 云 服 务 器 上 线 后 , 不 做 任 何 安 全 配 置 的 话 , 几 分 钟 内 就 会 被 僵 尸 网 络 扫 描 到 并 开 始 暴 力 破 解 S S H 。 以 下 是 新 服 务 器 必 须 完 成 的 1 0 项 安 全 加 固 。 < / p >
< h 2 > 1 . 禁 用 r o o t S S H 密 码 登 录 , 改 用 密 钥 < / h 2 > < p > 编 辑 < c o d e > / e t c / s s h / s s h d _ c o n f i g < / c o d e > : < c o d e > P e r m i t R o o t L o g i n p r o h i b i t - p a s s w o r d < / c o d e > ( 禁 止 r o o t 密 码 登 录 但 允 许 密 钥 登 录 ) 、 < c o d e > P a s s w o r d A u t h e n t i c a t i o n n o < / c o d e > ( 完 全 禁 止 密 码 登 录 , 强 制 密 钥 ) 。 重 启 s s h d : < c o d e > s y s t e m c t l r e s t a r t s s h d < / c o d e > 。 在 这 之 前 务 必 已 经 把 自 己 公 钥 添 加 到 < c o d e > ~ / . s s h / a u t h o r i z e d _ k e y s < / c o d e > , 否 则 你 自 己 也 进 不 去 了 。 < / p >
< h 2 > 2 . 修 改 S S H 默 认 端 口 < / h 2 > < p > 在 s s h d _ c o n f i g 中 < c o d e > P o r t 2 2 2 2 < / c o d e > ( 改 成 非 标 准 端 口 ) 。 这 不 能 阻 止 专 业 攻 击 者 用 n m a p 扫 描 到 , 但 能 过 滤 掉 9 9 % 的 自 动 化 扫 描 脚 本 。 如 果 用 了 U F W 防 火 墙 , 别 忘 了 开 放 新 端 口 : < c o d e > u f w a l l o w 2 2 2 2 / t c p < / c o d e > 。 < / p >
< h 2 > 3 . 安 装 f a i l 2 b a n < / h 2 > < p > < c o d e > a p t i n s t a l l f a i l 2 b a n < / c o d e > 。 默 认 配 置 就 能 自 动 检 测 S S H 暴 力 破 解 并 在 1 0 分 钟 内 封 禁 该 I P 。 可 以 配 置 邮 件 通 知 : 每 次 有 I P 被 封 就 发 邮 件 提 醒 你 。 < / p >
< h 2 > 4 . 配 置 防 火 墙 < / h 2 > < p > U F W ( U n c o m p l i c a t e d F i r e w a l l ) 是 最 易 用 的 i p t a b l e s 前 端 : < c o d e > u f w d e f a u l t d e n y i n c o m i n g < / c o d e > ( 默 认 拒 绝 入 站 ) → < c o d e > u f w d e f a u l t a l l o w o u t g o i n g < / c o d e > ( 默 认 允 许 出 站 ) → < c o d e > u f w a l l o w 2 2 2 2 / t c p < / c o d e > ( S S H ) → < c o d e > u f w a l l o w 8 0 / t c p < / c o d e > 和 < c o d e > u f w a l l o w 4 4 3 / t c p < / c o d e > ( W e b ) → < c o d e > u f w e n a b l e < / c o d e > 。 检 查 状 态 : < c o d e > u f w s t a t u s v e r b o s e < / c o d e > 。 < / p >
< h 2 > 5 - 1 0 . 其 他 关 键 措 施 < / h 2 > < p > 5 . 禁 用 不 必 要 的 服 务 : < c o d e > s y s t e m c t l l i s t - u n i t s - - t y p e = s e r v i c e < / c o d e > 检 查 运 行 中 的 服 务 , 禁 用 不 需 要 的 。 6 . 保 持 系 统 更 新 : < c o d e > a p t u p d a t e & & a p t u p g r a d e - y < / c o d e > 每 周 执 行 一 次 。 7 . 配 置 自 动 安 全 更 新 : < c o d e > a p t i n s t a l l u n a t t e n d e d - u p g r a d e s < / c o d e > 自 动 安 装 安 全 补 丁 。 8 . 创 建 普 通 用 户 并 赋 予 s u d o 权 限 : 日 常 操 作 不 用 r o o t 。 9 . 禁 用 I P v 6 ( 如 果 不 需 要 ) : 在 s y s c t l . c o n f 中 设 置 禁 用 。 1 0 . 安 装 并 配 置 a u d i t d 审 计 日 志 : 记 录 关 键 文 件 的 访 问 和 修 改 。 < / p >

💬 暂无评论