{"id":95958,"date":"2026-08-27T07:25:01","date_gmt":"2026-08-26T23:25:01","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/95958.html"},"modified":"2026-08-27T07:25:01","modified_gmt":"2026-08-26T23:25:01","slug":"%e6%9c%8d%e5%8a%a1%e5%99%a8%e8%a2%ab%e6%94%bb%e5%87%bb%ef%bc%81%e5%ae%8c%e6%95%b4%e5%ae%89%e5%85%a8%e5%8a%a0%e5%9b%ba%e6%b8%85%e5%8d%95%e6%b1%87%e6%80%bb","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/95958.html","title":{"rendered":"\u670d\u52a1\u5668\u88ab\u653b\u51fb\uff01\u5b8c\u6574\u5b89\u5168\u52a0\u56fa\u6e05\u5355\u6c47\u603b"},"content":{"rendered":"<h2>\u670d\u52a1\u5668\u88ab\u653b\u51fb&#xff01;\u5b8c\u6574\u5b89\u5168\u52a0\u56fa\u6e05\u5355\u6c47\u603b<\/h2>\n<p>\u670d\u52a1\u5668\u88ab\u9ed1\u4e0d\u662f\u5c0f\u6982\u7387\u4e8b\u4ef6\u3002\u53ea\u8981\u670d\u52a1\u5668\u66b4\u9732\u5728\u516c\u7f51&#xff0c;\u6bcf\u65f6\u6bcf\u523b\u90fd\u5728\u88ab\u626b\u63cf\u3001\u88ab\u5c1d\u8bd5\u5f31\u53e3\u4ee4\u3001\u88ab\u63a2\u6d4b\u6f0f\u6d1e\u3002\u5b89\u5168\u52a0\u56fa\u4e0d\u662f&#034;\u7528\u4e0d\u7528\u5fc3&#034;\u7684\u95ee\u9898&#xff0c;\u800c\u662f&#034;\u6709\u6ca1\u6709\u505a&#034;\u7684\u95ee\u9898\u3002\u8fd9\u7bc7\u6587\u7ae0\u7ed9\u51fa\u4e00\u4efd\u5b8c\u6574\u7684 Linux \u670d\u52a1\u5668\u5b89\u5168\u52a0\u56fa\u6e05\u5355&#xff0c;\u6db5\u76d6\u8d26\u6237\u5b89\u5168\u3001SSH \u52a0\u56fa\u3001\u9632\u706b\u5899\u914d\u7f6e\u3001\u670d\u52a1\u5b89\u5168\u3001\u65e5\u5fd7\u5ba1\u8ba1\u3001\u5165\u4fb5\u68c0\u6d4b\u7b49\u6838\u5fc3\u73af\u8282\u3002\u6bcf\u4e2a\u6761\u76ee\u90fd\u8bb2\u89e3\u4e3a\u4ec0\u4e48\u8981\u505a\u3001\u600e\u4e48\u505a\u3001\u4e0d\u505a\u7684\u98ce\u9669\u662f\u4ec0\u4e48&#xff0c;\u8ba9\u521d\u4e2d\u7ea7\u8fd0\u7ef4\u5de5\u7a0b\u5e08\u80fd\u7167\u7740\u64cd\u4f5c\u3001\u843d\u5730\u6267\u884c\u3002<\/p>\n<h3>1. \u4ec0\u4e48\u65f6\u5019\u9700\u8981\u505a\u5b89\u5168\u52a0\u56fa<\/h3>\n<p>\u5b89\u5168\u52a0\u56fa\u5e94\u8be5\u5728\u670d\u52a1\u5668\u4e0a\u7ebf\u524d\u5c31\u5b8c\u6210&#xff0c;\u800c\u4e0d\u662f\u7b49\u5230\u88ab\u9ed1\u4e4b\u540e\u3002\u4ee5\u4e0b\u51e0\u4e2a\u8282\u70b9\u5fc5\u987b\u505a\u5b89\u5168\u52a0\u56fa&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u65b0\u670d\u52a1\u5668\u4ea4\u4ed8\u540e\u3001\u4e0a\u7ebf\u524d&#xff1a;\u670d\u52a1\u5668\u9ed8\u8ba4\u914d\u7f6e\u9762\u5411\u6613\u7528\u6027&#xff0c;\u4e0d\u9762\u5411\u5b89\u5168\u3002<\/p>\n<\/li>\n<li>\n<p>\u7cfb\u7edf\u91cd\u88c5\u6216\u91cd\u5927\u53d8\u66f4\u540e&#xff1a;\u7cfb\u7edf\u53d8\u66f4\u53ef\u80fd\u91cd\u7f6e\u5b89\u5168\u914d\u7f6e\u3002<\/p>\n<\/li>\n<li>\n<p>\u6f0f\u6d1e\u7206\u53d1\u540e&#xff1a;\u5982 OpenSSH RCE&#xff08;CVE-2024-6387&#xff09;\u3001Linux \u5185\u6838\u63d0\u6743\u6f0f\u6d1e\u7b49\u3002<\/p>\n<\/li>\n<li>\n<p>\u901a\u8fc7\u7b49\u4fdd\u6d4b\u8bc4\u524d&#xff1a;\u7b49\u7ea7\u4fdd\u62a4\u8981\u6c42\u660e\u786e\u7684\u5b89\u5168\u57fa\u7ebf\u3002<\/p>\n<\/li>\n<li>\n<p>\u670d\u52a1\u5668\u88ab\u9ed1\u540e\u590d\u76d8\u65f6&#xff1a;\u88ab\u9ed1\u8bf4\u660e\u5b58\u5728\u5b89\u5168\u7f3a\u53e3&#xff0c;\u9700\u8981\u4ea1\u7f8a\u8865\u7262\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u672c\u6587\u9002\u7528\u4e8e CentOS\/RHEL 7\/8\/9\u3001Ubuntu 18.04\/20.04\/22.04\u3001Debian 10\/11\/12 \u7b49\u4e3b\u6d41\u53d1\u884c\u7248\u3002<\/p>\n<h3>2. \u52a0\u56fa\u524d\u7684\u51c6\u5907\u5de5\u4f5c<\/h3>\n<p>\u52a0\u56fa\u662f\u9ad8\u98ce\u9669\u64cd\u4f5c&#xff0c;\u914d\u7f6e\u9519\u8bef\u53ef\u80fd\u5bfc\u81f4\u670d\u52a1\u5668\u65e0\u6cd5\u767b\u5f55\u6216\u670d\u52a1\u4e2d\u65ad\u3002\u64cd\u4f5c\u524d\u5fc5\u987b\u5b8c\u6210\u4ee5\u4e0b\u51c6\u5907&#xff1a;<\/p>\n<h4>2.1 \u5907\u4efd\u5f53\u524d\u914d\u7f6e<\/h4>\n<p># \u5907\u4efd\u6240\u6709\u5373\u5c06\u4fee\u6539\u7684\u914d\u7f6e\u6587\u4ef6<br \/>\nmkdir \/opt\/security-hardening-backup-$(date &#043;%Y%m%d)<br \/>\ncd\u00a0\/opt\/security-hardening-backup-$(date &#043;%Y%m%d)<\/p>\n<p># \u5907\u4efd\u7cfb\u7edf\u5173\u952e\u914d\u7f6e<br \/>\ncp \/etc\/ssh\/sshd_config .\/sshd_config.bak<br \/>\ncp \/etc\/pam.d\/system-auth .\/system-auth.bak<br \/>\ncp \/etc\/login.defs .\/login.defs.bak<br \/>\ncp \/etc\/fstab .\/fstab.bak<br \/>\ncp \/etc\/sysctl.conf .\/sysctl.conf.bak<br \/>\ncp \/etc\/rsyslog.conf .\/rsyslog.conf.bak<br \/>\ncp \/etc\/hosts.allow .\/hosts.allow.bak<br \/>\ncp \/etc\/hosts.deny .\/hosts.deny.bak<br \/>\ncp \/etc\/passwd .\/passwd.bak<br \/>\ncp \/etc\/shadow .\/shadow.bak<br \/>\ncp \/etc\/group .\/group.bak<br \/>\ncp -r \/etc\/iptables* .\/iptables.bak 2&gt;\/dev\/null ||\u00a0true<\/p>\n<p># \u5907\u4efd systemd \u670d\u52a1\u5217\u8868<br \/>\nsystemctl list-units &#8211;type&#061;service &#8211;all &gt; services-backup.txt<\/p>\n<p># \u8bb0\u5f55\u5f53\u524d\u8fd0\u884c\u7684\u8fdb\u7a0b\u548c\u7f51\u7edc\u8fde\u63a5&#xff08;\u57fa\u7ebf&#xff09;<br \/>\nps auxf &gt; processes-backup.txt<br \/>\nnetstat -tulnp &gt; listening-ports-backup.txt<br \/>\nss -tulnp &gt; ss-backup.txt<\/p>\n<p># \u8bb0\u5f55\u5f53\u524d\u7528\u6237\u548c\u6743\u9650<br \/>\ncat \/etc\/passwd &gt; users-backup.txt<br \/>\ncat \/etc\/group &gt; groups-backup.txt<br \/>\ngetent shadow &gt; shadow-backup.txt<\/p>\n<p>echo&#034;Backup completed. Files are in \/opt\/security-hardening-backup-$(date &#043;%Y%m%d)&#034;<\/p>\n<h4>2.2 \u521b\u5efa\u4e91\u670d\u52a1\u5668\u5feb\u7167&#xff08;\u5f3a\u70c8\u5efa\u8bae&#xff09;<\/h4>\n<p>\u4e91\u670d\u52a1\u5668&#xff08;\u963f\u91cc\u4e91\u3001\u817e\u8baf\u4e91\u3001AWS \u7b49&#xff09;\u652f\u6301\u521b\u5efa\u5feb\u7167&#xff0c;\u8fd9\u4e00\u6b65\u4e0d\u80fd\u7701&#xff1a;<\/p>\n<p># \u963f\u91cc\u4e91 CLI \u521b\u5efa\u5feb\u7167&#xff08;\u9700\u8981\u5148\u5b89\u88c5 aliyun CLI \u5e76\u914d\u7f6e AK&#xff09;<br \/>\naliyun ecs CreateSnapshot &#8211;DiskId disk-xxx &#8211;Description\u00a0&#034;pre-security-hardening-$(date &#043;%Y%m%d)&#034;<\/p>\n<p># \u817e\u8baf\u4e91 CLI<br \/>\n# qcloudcli cvm CreateSnapshot &#8211;instanceId ins-xxx &#8211;snapshotName &#034;pre-hardening-$(date &#043;%Y%m%d)&#034;<\/p>\n<p># AWS CLI<br \/>\n# aws ec2 create-snapshot &#8211;description &#034;pre-hardening-$(date &#043;%Y%m%d)&#034; &#8211;volume-id vol-xxx<\/p>\n<p>\u5feb\u7167\u662f\u670d\u52a1\u5668\u78c1\u76d8\u7684\u5b8c\u6574\u526f\u672c&#xff0c;\u51fa\u95ee\u9898\u53ef\u4ee5\u56de\u6eda&#xff0c;\u6bd4\u5907\u4efd\u914d\u7f6e\u6587\u4ef6\u66f4\u4fdd\u9669\u3002<\/p>\n<h4>2.3 \u51c6\u5907\u7d27\u6025\u6551\u63f4\u65b9\u5f0f<\/h4>\n<p>\u786e\u4fdd\u4f60\u8fd8\u6709\u9664\u4e86 SSH \u4ee5\u5916\u7684\u767b\u5f55\u65b9\u5f0f&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4e91\u63a7\u5236\u53f0 VNC\/\u8fdc\u7a0b\u767b\u5f55&#xff08;\u5e94\u6025\u5165\u53e3&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7269\u7406\u670d\u52a1\u5668\u4f7f\u7528 IPMI\/iLO\/iDRAC<\/p>\n<\/li>\n<li>\n<p>\u63d0\u524d\u51c6\u5907\u4e00\u4e2a\u53ef\u4ee5\u901a\u8fc7\u4e91\u63a7\u5236\u53f0\u6267\u884c\u7684\u811a\u672c<\/p>\n<\/li>\n<\/ul>\n<h4>2.4 \u6d4b\u8bd5\u7a97\u53e3<\/h4>\n<p>\u5b89\u5168\u52a0\u56fa\u6700\u597d\u5728\u7ef4\u62a4\u7a97\u53e3\u8fdb\u884c&#xff0c;\u786e\u4fdd&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4e1a\u52a1\u4f4e\u5cf0\u671f&#xff0c;\u4e0d\u4f1a\u5f71\u54cd\u592a\u591a\u7528\u6237<\/p>\n<\/li>\n<li>\n<p>\u6709\u8db3\u591f\u65f6\u95f4\u6392\u67e5\u52a0\u56fa\u540e\u7684\u5f02\u5e38<\/p>\n<\/li>\n<li>\n<p>\u6709\u4eba\u503c\u5b88&#xff0c;\u51fa\u95ee\u9898\u80fd\u53ca\u65f6\u54cd\u5e94<\/p>\n<\/li>\n<li>\n<p>\u5df2\u7ecf\u901a\u77e5\u76f8\u5173\u65b9&#xff08;\u4e1a\u52a1\u65b9\u3001Leader&#xff09;<\/p>\n<\/li>\n<\/ul>\n<h3>3. \u8d26\u6237\u4e0e\u5bc6\u7801\u5b89\u5168<\/h3>\n<h4>3.1 \u68c0\u67e5\u662f\u5426\u6709\u5f31\u5bc6\u7801\u8d26\u6237<\/h4>\n<p># \u5217\u51fa\u6240\u6709\u7cfb\u7edf\u8d26\u6237&#xff08;\u975e\u767b\u5f55\u3001\u975e\u670d\u52a1\u8d26\u53f7\u9664\u5916&#xff09;<br \/>\nawk -F:\u00a0&#039;{print $1, $3, $7}&#039;\u00a0\/etc\/passwd | grep -vE\u00a0&#034;(nologin|false|sync)&#034;\u00a0| head -50<\/p>\n<p># \u68c0\u67e5\u662f\u5426\u6709\u7a7a\u5bc6\u7801\u8d26\u6237<br \/>\nawk -F:\u00a0&#039;($2&#061;&#061;&#034;&#034;) {print $1}&#039;\u00a0\/etc\/shadow<\/p>\n<p># \u68c0\u67e5\u5bc6\u7801\u7b56\u7565<br \/>\ncat \/etc\/login.defs | grep -E\u00a0&#034;(PASS_MIN_LEN|PASS_MAX_DAYS|PASS_MIN_DAYS|PASS_WARN_AGE)&#034;<\/p>\n<p># \u67e5\u770b\u5f53\u524d\u5bc6\u7801\u7b56\u7565&#xff08;CentOS\/RHEL&#xff09;<br \/>\nauthconfig &#8211;test\u00a0| grep password<br \/>\n# \u6216<br \/>\npam_cracklib &#8211;test<\/p>\n<h4>3.2 \u8bbe\u7f6e\u5bc6\u7801\u7b56\u7565<\/h4>\n<p>\u4fee\u6539\u00a0\/etc\/login.defs&#xff08;\u5bf9\u65b0\u7528\u6237\u751f\u6548&#xff09;&#xff1a;<\/p>\n<p># \/etc\/login.defs<br \/>\nPASS_MAX_DAYS \u00a0 90 \u00a0 \u00a0 \u00a0 \u00a0# \u5bc6\u7801\u6700\u957f\u4f7f\u7528 90 \u5929<br \/>\nPASS_MIN_DAYS \u00a0 7 \u00a0 \u00a0 \u00a0 \u00a0\u00a0# \u5bc6\u7801\u6700\u5c11\u4f7f\u7528 7 \u5929\u624d\u80fd\u4fee\u6539<br \/>\nPASS_MIN_LEN \u00a0 \u00a012 \u00a0 \u00a0 \u00a0 \u00a0# \u5bc6\u7801\u6700\u5c0f\u957f\u5ea6 12 \u4f4d&#xff08;\u6ce8\u610f&#xff1a;\u5b9e\u9645\u7531 PAM \u6a21\u5757\u63a7\u5236&#xff09;<br \/>\nPASS_WARN_AGE \u00a0 14 \u00a0 \u00a0 \u00a0 \u00a0# \u5bc6\u7801\u5230\u671f\u524d 14 \u5929\u8b66\u544a<\/p>\n<p>\u4fee\u6539 PAM \u6a21\u5757\u5bc6\u7801\u7b56\u7565&#xff08;\u5bf9\u73b0\u6709\u7528\u6237\u4e5f\u751f\u6548&#xff0c;CentOS\/RHEL&#xff09;&#xff1a;<\/p>\n<p># \/etc\/security\/pwquality.conf \u6216 \/etc\/pam.d\/password-auth<br \/>\n# \u627e\u5230 password requisite pam_pwquality.so \u884c&#xff0c;\u6539\u4e3a&#xff1a;<br \/>\npassword requisite pam_pwquality.so try_first_pass local_users_only retry&#061;3 \\\\<br \/>\n\u00a0 \u00a0 minlen&#061;12 dcredit&#061;-1 ucredit&#061;-1 lcredit&#061;-1 ocredit&#061;-1 \\\\<br \/>\n\u00a0 \u00a0 enforce_for_root<\/p>\n<p># \u542b\u4e49&#xff1a;<br \/>\n# minlen&#061;12 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u6700\u5c0f\u957f\u5ea6 12 \u4f4d<br \/>\n# dcredit&#061;-1 \u00a0 \u00a0 \u00a0 \u00a0\u81f3\u5c11\u5305\u542b 1 \u4e2a\u6570\u5b57&#xff08;dcredit \u8d1f\u6570\u8868\u793a&#034;\u81f3\u5c11&#034;&#xff09;<br \/>\n# ucredit&#061;-1 \u00a0 \u00a0 \u00a0 \u00a0\u81f3\u5c11\u5305\u542b 1 \u4e2a\u5927\u5199\u5b57\u6bcd<br \/>\n# lcredit&#061;-1 \u00a0 \u00a0 \u00a0 \u00a0\u81f3\u5c11\u5305\u542b 1 \u4e2a\u5c0f\u5199\u5b57\u6bcd<br \/>\n# ocredit&#061;-1 \u00a0 \u00a0 \u00a0 \u00a0\u81f3\u5c11\u5305\u542b 1 \u4e2a\u7279\u6b8a\u5b57\u7b26<br \/>\n# enforce_for_root \u00a0root \u7528\u6237\u4e5f\u5f3a\u5236\u6267\u884c<\/p>\n<p>Ubuntu\/Debian \u4e2d\u7f16\u8f91\u00a0\/etc\/security\/pwquality.conf\u00a0\u6216\u00a0\/etc\/pam.d\/common-password&#xff1a;<\/p>\n<p>password requisite pam_pwquality.so retry&#061;3 minlen&#061;12 ucredit&#061;-1 lcredit&#061;-1 dcredit&#061;-1 ocredit&#061;-1<\/p>\n<h4>3.3 \u9501\u5b9a\u4e0d\u5e94\u767b\u5f55\u7684\u7cfb\u7edf\u8d26\u6237<\/h4>\n<p>\u5f88\u591a\u670d\u52a1\u4f1a\u521b\u5efa\u7cfb\u7edf\u8d26\u6237&#xff0c;\u8fd9\u4e9b\u8d26\u6237\u4e0d\u5e94\u8be5\u7528\u4e8e\u767b\u5f55&#xff1a;<\/p>\n<p># \u9501\u5b9a\u4e0d\u9700\u8981\u767b\u5f55\u7684\u8d26\u6237<br \/>\nfor\u00a0user\u00a0in\u00a0bin daemon news uucp games gnats smmsp nobody nfsnobody;\u00a0do<br \/>\n\u00a0 \u00a0 usermod -L\u00a0$user\u00a02&gt;\/dev\/null &amp;&amp;\u00a0echo\u00a0&#034;Locked\u00a0$user&#034;\u00a0||\u00a0echo\u00a0&#034;$user\u00a0not found or already locked&#034;<br \/>\ndone<\/p>\n<p># \u68c0\u67e5\u662f\u5426\u8fd8\u6709\u8d26\u6237\u662f \/bin\/bash \u767b\u5f55<br \/>\nawk -F:\u00a0&#039;{print $1, $7}&#039;\u00a0\/etc\/passwd | grep -E\u00a0&#034;bash$&#034;\u00a0| grep -v -E\u00a0&#034;^(root|admin|deploy|app):&#034;<\/p>\n<p># \u786e\u4fdd root \u8d26\u6237\u4e0d\u80fd\u901a\u8fc7 SSH \u767b\u5f55<br \/>\n# \u8fd9\u4e2a\u5728 SSH \u52a0\u56fa\u90e8\u5206\u4f1a\u8be6\u7ec6\u8bf4<\/p>\n<h4>3.4 \u9650\u5236 su \u547d\u4ee4\u4f7f\u7528<\/h4>\n<p>\u53ea\u5141\u8bb8\u7279\u5b9a\u7528\u6237\u4f7f\u7528 su \u5207\u6362\u5230 root&#xff1a;<\/p>\n<p># \u5728 \/etc\/pam.d\/su \u4e2d\u6dfb\u52a0&#xff08;\u9ed8\u8ba4\u5df2\u6709\u6ce8\u91ca&#xff0c;\u53d6\u6d88\u6ce8\u91ca\u5373\u53ef&#xff09;<br \/>\n# auth required pam_wheel.so use_uid<\/p>\n<p># \u5c06\u4fe1\u4efb\u7684\u7528\u6237\u52a0\u5165 wheel \u7ec4<br \/>\nusermod -aG wheel admin_user<\/p>\n<p># \u9a8c\u8bc1 wheel \u7ec4\u914d\u7f6e<br \/>\ngrep\u00a0&#034;^wheel&#034;\u00a0\/etc\/group<\/p>\n<p># \u6d4b\u8bd5&#xff1a;\u975e wheel \u7ec4\u7528\u6237\u4e0d\u80fd su &#8211;<br \/>\nsu &#8211; admin_user \u00a0# \u5148\u5207\u6362\u5230\u666e\u901a\u7528\u6237<br \/>\nsu &#8211; root \u00a0 \u00a0 \u00a0 \u00a0# \u5e94\u8be5\u62a5\u9519&#xff1a;Permission denied<\/p>\n<h4>3.5 \u8e22\u51fa\u5df2\u767b\u5f55\u7684\u5f02\u5e38\u7528\u6237<\/h4>\n<p># \u67e5\u770b\u5f53\u524d\u767b\u5f55\u7528\u6237<br \/>\nwho<br \/>\nw<br \/>\nlast<\/p>\n<p># \u8e22\u51fa\u5f02\u5e38\u767b\u5f55&#xff08;\u5047\u8bbe\u53d1\u73b0 hack user&#xff09;<br \/>\npkill -KILL -u hack_user<\/p>\n<p># \u7acb\u5373\u7981\u7528\u8be5\u8d26\u6237<br \/>\nusermod -L hack_user<br \/>\nusermod -s \/sbin\/nologin hack_user<\/p>\n<h3>4. SSH \u5b89\u5168\u52a0\u56fa<\/h3>\n<p>SSH \u662f\u670d\u52a1\u5668\u88ab\u5165\u4fb5\u7684\u6700\u4e3b\u8981\u5165\u53e3\u3002\u5927\u91cf\u653b\u51fb\u8005\u7528\u5f31\u53e3\u4ee4\u5b57\u5178\u6279\u91cf\u626b SSH\u3002SSH \u52a0\u56fa\u662f\u5b89\u5168\u52a0\u56fa\u4e2d\u6700\u91cd\u8981\u7684\u4e00\u73af\u3002<\/p>\n<h4>4.1 \u4fee\u6539 SSH \u9ed8\u8ba4\u7aef\u53e3<\/h4>\n<p>SSH \u9ed8\u8ba4\u76d1\u542c 22 \u7aef\u53e3&#xff0c;\u5168\u4e16\u754c\u626b\u63cf\u5668\u90fd\u5728\u626b 22\u3002\u6539\u6210\u9ad8\u4f4d\u7aef\u53e3\u80fd\u51cf\u5c11 99% \u7684\u626b\u63cf\u6d41\u91cf&#xff1a;<\/p>\n<p># \u7f16\u8f91 \/etc\/ssh\/sshd_config<br \/>\nPort 22022 \u00a0# \u4e0d\u8981\u7528 2222&#xff0c;\u6709\u4e9b\u626b\u63cf\u5668\u4e5f\u4f1a\u626b<\/p>\n<p># \u4fee\u6539\u540e\u91cd\u542f SSH<br \/>\nsystemctl restart sshd<\/p>\n<p># \u6ce8\u610f&#xff1a;\u4fee\u6539\u7aef\u53e3\u540e&#xff0c;\u540e\u7eed SSH \u8fde\u63a5\u9700\u8981\u6307\u5b9a\u7aef\u53e3<br \/>\nssh -p 22022 root&#064;server_ip<\/p>\n<p># \u9632\u706b\u5899\u653e\u884c\u65b0\u7aef\u53e3&#xff08;\u7a0d\u540e\u9632\u706b\u5899\u90e8\u5206\u4f1a\u8bb2&#xff09;<\/p>\n<p>\u98ce\u9669\u63d0\u9192&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6539\u5b8c\u7aef\u53e3\u540e\u786e\u4fdd\u5f53\u524d SSH \u4f1a\u8bdd\u4e0d\u65ad&#xff08;\u65b0\u7aef\u53e3\u751f\u6548\u540e\u518d\u9000\u51fa&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u4fee\u6539\u7aef\u53e3\u540e\u76d1\u63a7\u5de5\u5177&#xff08;\u5982 ansible&#xff09;\u9700\u8981\u540c\u6b65\u66f4\u65b0\u3002<\/p>\n<\/li>\n<li>\n<p>\u9ad8\u4f4d\u7aef\u53e3&#xff08;\u5982 22022&#xff09;\u53ef\u80fd\u4e0e\u4f01\u4e1a\u5185\u7f51\u7b56\u7565\u51b2\u7a81&#xff0c;\u6ce8\u610f\u8bc4\u4f30\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>4.2 \u7981\u7528 root \u76f4\u63a5\u767b\u5f55<\/h4>\n<p>root \u662f\u6700\u9ad8\u6743\u9650\u8d26\u6237&#xff0c;\u7981\u7528\u76f4\u63a5\u767b\u5f55&#xff0c;\u5f3a\u5236\u4f7f\u7528\u666e\u901a\u7528\u6237 &#043; sudo&#xff1a;<\/p>\n<p># \/etc\/ssh\/sshd_config<br \/>\nPermitRootLogin no<\/p>\n<p># \u786e\u4fdd\u6709\u53ef\u7528\u7684 sudo \u7528\u6237<br \/>\nuseradd -m -s \/bin\/bash admin_user<br \/>\nusermod -aG wheel admin_user<br \/>\necho\u00a0&#034;admin_user:Str0ngP&#064;ssw0rd&#034;\u00a0| chpasswd<\/p>\n<p># \u6d4b\u8bd5\u65b0\u7528\u6237\u53ef\u4ee5 sudo<br \/>\nssh admin_user&#064;server_ip<br \/>\nsudo -l \u00a0# \u5e94\u8be5\u663e\u793a admin_user can run commands<\/p>\n<h4>4.3 \u4f7f\u7528\u5bc6\u94a5\u767b\u5f55&#xff0c;\u7981\u6b62\u5bc6\u7801\u767b\u5f55<\/h4>\n<p>\u5bc6\u94a5\u767b\u5f55\u4ece\u6839\u672c\u4e0a\u675c\u7edd\u4e86\u66b4\u529b\u7834\u89e3\u3002\u5bc6\u7801\u767b\u5f55\u5373\u4f7f\u518d\u590d\u6742&#xff0c;\u4e5f\u662f\u53ef\u88ab\u7834\u89e3\u7684&#xff1a;<\/p>\n<p># \u5728\u672c\u5730\u673a\u5668&#xff08;\u4f60\u7684\u7b14\u8bb0\u672c\/\u53f0\u5f0f\u673a&#xff09;\u751f\u6210\u5bc6\u94a5\u5bf9<br \/>\nssh-keygen -t ed25519 -C\u00a0&#034;your_email&#064;example.com&#034;\u00a0-f ~\/.ssh\/id_ed25519_server<\/p>\n<p># \u5c06\u516c\u94a5\u4e0a\u4f20\u5230\u670d\u52a1\u5668<br \/>\nssh-copy-id -i ~\/.ssh\/id_ed25519_server.pub -p 22022 admin_user&#064;server_ip<\/p>\n<p># \u6216\u8005\u624b\u52a8\u8ffd\u52a0<br \/>\n# cat ~\/.ssh\/id_ed25519_server.pub | ssh -p 22022 admin_user&#064;server_ip &#034;mkdir -p ~\/.ssh &amp;&amp; chmod 700 ~\/.ssh &amp;&amp; cat &gt;&gt; ~\/.ssh\/authorized_keys &amp;&amp; chmod 600 ~\/.ssh\/authorized_keys&#034;<\/p>\n<p># \u4fee\u6539 SSH \u914d\u7f6e<br \/>\n# \/etc\/ssh\/sshd_config<br \/>\nPubkeyAuthentication yes<br \/>\nPasswordAuthentication no<br \/>\nPermitEmptyPasswords no<br \/>\nChallengeResponseAuthentication no<\/p>\n<p># \u91cd\u542f SSH<br \/>\nsystemctl restart sshd<\/p>\n<h4>4.4 \u9650\u5236\u53ef\u767b\u5f55\u7528\u6237\u548c IP<\/h4>\n<p># \/etc\/ssh\/sshd_config<br \/>\nAllowUsers admin_user deploy_user&#064;10.0.0.0\/8 admin_user&#064;192.168.1.0\/24<\/p>\n<p># \u53ea\u5141\u8bb8\u7279\u5b9a\u7ec4<br \/>\nAllowGroups wheel admin<\/p>\n<p># \u9650\u5236 sshd \u76d1\u542c\u5730\u5740&#xff08;\u53ea\u76d1\u542c\u5185\u7f51 IP&#xff0c;\u4e0d\u76d1\u542c\u516c\u7f51&#xff09;<br \/>\nListenAddress 0.0.0.0 \u00a0# \u9ed8\u8ba4&#xff0c;\u5efa\u8bae\u6539\u4e3a\u5185\u7f51\u5730\u5740<br \/>\n# ListenAddress 10.0.0.100<\/p>\n<h4>4.5 \u5176\u4ed6 SSH \u5b89\u5168\u53c2\u6570<\/h4>\n<p># \/etc\/ssh\/sshd_config \u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9<br \/>\n# \u7981\u7528\u7a7a\u5bc6\u7801<br \/>\nPermitEmptyPasswords no<\/p>\n<p># \u7981\u7528 .rhosts \u6587\u4ef6<br \/>\nIgnoreRhosts yes<\/p>\n<p># \u7981\u7528\u57fa\u4e8e\u4e3b\u673a\u7684\u8ba4\u8bc1<br \/>\nHostbasedAuthentication no<\/p>\n<p># \u5173\u95ed X11 \u8f6c\u53d1&#xff08;\u9664\u975e\u771f\u7684\u9700\u8981&#xff09;<br \/>\nX11Forwarding no<\/p>\n<p># \u5173\u95ed TCP \u8f6c\u53d1&#xff08;\u9632\u6b62 SSH \u88ab\u7528\u4f5c\u4ee3\u7406&#xff09;<br \/>\nAllowTcpForwarding no<\/p>\n<p># \u5173\u95ed Agent \u8f6c\u53d1<br \/>\nAllowAgentForwarding no<\/p>\n<p># \u8bbe\u7f6e\u7a7a\u95f2\u8d85\u65f6&#xff08;\u5ba2\u6237\u7aef 10 \u5206\u949f\u65e0\u64cd\u4f5c\u81ea\u52a8\u65ad\u5f00&#xff09;<br \/>\nClientAliveInterval 600<br \/>\nClientAliveCountMax 2<\/p>\n<p># \u9650\u5236\u6700\u5927\u8ba4\u8bc1\u5c1d\u8bd5\u6b21\u6570<br \/>\nMaxAuthTries 3<\/p>\n<p># \u8bbe\u7f6e\u767b\u5f55\u6210\u529f\u540e\u7684 Banner&#xff08;\u53ef\u9009&#xff0c;\u8d77\u5230\u5a01\u6151\u4f5c\u7528&#xff09;<br \/>\nPrintMotd yes<br \/>\nPrintLastLog yes<\/p>\n<p># SSH \u534f\u8bae\u7248\u672c&#xff08;\u5fc5\u987b\u4e3a 2&#xff09;<br \/>\nProtocol 2<\/p>\n<h4>4.6 \u4f7f\u7528 fail2ban \u9632\u6b62\u66b4\u529b\u7834\u89e3<\/h4>\n<p>\u5373\u4f7f\u505a\u4e86\u4ee5\u4e0a\u52a0\u56fa&#xff0c;\u653b\u51fb\u8005\u4ecd\u53ef\u80fd\u5c1d\u8bd5\u5bc6\u94a5\u7834\u89e3\u6216\u5185\u90e8\u8d26\u6237\u5f31\u53e3\u4ee4\u3002fail2ban \u80fd\u81ea\u52a8\u5c01\u7981\u9891\u7e41\u5c1d\u8bd5\u767b\u5f55\u7684 IP&#xff1a;<\/p>\n<p># CentOS\/RHEL \u5b89\u88c5<br \/>\nyum install -y epel-release<br \/>\nyum install -y fail2ban<\/p>\n<p># Ubuntu\/Debian \u5b89\u88c5<br \/>\napt install -y fail2ban<\/p>\n<p># \u914d\u7f6e fail2ban&#xff08;\u4e0d\u4fee\u6539 \/etc\/fail2ban\/jail.conf&#xff0c;\u521b\u5efa local \u8986\u76d6\u6587\u4ef6&#xff09;<br \/>\ncat &gt; \/etc\/fail2ban\/jail.local &lt;&lt;\u00a0&#039;EOF&#039;<br \/>\n[DEFAULT]<br \/>\nbantime &#061; 3600 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0# \u5c01\u7981 1 \u5c0f\u65f6<br \/>\nfindtime &#061; 600 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0# 10 \u5206\u949f\u5185<br \/>\nmaxretry &#061; 3 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0# \u5931\u8d25 3 \u6b21\u5373\u5c01\u7981<br \/>\nignoreip &#061; 127.0.0.1\/8 10.0.0.0\/8 192.168.0.0\/16 \u00a0# \u4e0d\u5c01\u7981\u8fd9\u4e9b IP<\/p>\n<p>[sshd]<br \/>\nenabled &#061;\u00a0true<br \/>\nport &#061; 22022<br \/>\nfilter &#061; sshd<br \/>\nlogpath &#061; \/var\/log\/secure \u00a0# CentOS\/RHEL<br \/>\n# logpath &#061; \/var\/log\/auth.log \u00a0# Ubuntu\/Debian<br \/>\nmaxretry &#061; 3<\/p>\n<p>[sshd-ddos]<br \/>\nenabled &#061;\u00a0true<br \/>\nport &#061; 22022<br \/>\nfilter &#061; sshd-ddos<br \/>\nlogpath &#061; \/var\/log\/secure<br \/>\nmaxretry &#061; 10<br \/>\nEOF<\/p>\n<p># \u542f\u52a8\u5e76\u8bbe\u7f6e\u5f00\u673a\u81ea\u542f<br \/>\nsystemctl\u00a0enable\u00a0fail2ban<br \/>\nsystemctl start fail2ban<\/p>\n<p># \u67e5\u770b\u88ab\u5c01\u7981\u7684 IP<br \/>\nfail2ban-client status sshd<br \/>\nfail2ban-client banned sshd<\/p>\n<p># \u624b\u52a8\u89e3\u5c01\u67d0\u4e2a IP<br \/>\nfail2ban-client\u00a0set\u00a0sshd unbanip 192.168.1.100<\/p>\n<h4>4.7 \u9a8c\u8bc1 SSH \u52a0\u56fa\u6548\u679c<\/h4>\n<p># \u68c0\u67e5\u5f53\u524d SSH \u914d\u7f6e\u662f\u5426\u6b63\u786e<br \/>\nsshd -t<\/p>\n<p># \u67e5\u770b SSH \u76d1\u542c\u7aef\u53e3<br \/>\nss -tulnp | grep sshd<\/p>\n<p># \u67e5\u770b\u8c01\u66fe\u7ecf\u767b\u5f55\u8fc7&#xff08;\u7528\u4e8e\u5ba1\u8ba1&#xff09;<br \/>\nlast<br \/>\nlastlog | head -50<\/p>\n<p># \u67e5\u770b SSH \u5931\u8d25\u767b\u5f55\u8bb0\u5f55<br \/>\n# CentOS\/RHEL<br \/>\ncat \/var\/log\/secure | grep -i\u00a0&#034;failed password&#034;\u00a0| tail -50<br \/>\n# Ubuntu\/Debian<br \/>\ncat \/var\/log\/auth.log | grep -i\u00a0&#034;failed password&#034;\u00a0| tail -50<\/p>\n<p># \u67e5\u770b fail2ban \u65e5\u5fd7<br \/>\ntail -100 \/var\/log\/fail2ban.log<\/p>\n<h3>5. \u6587\u4ef6\u7cfb\u7edf\u6743\u9650<\/h3>\n<h4>5.1 \u8bbe\u7f6e \/tmp\u3001\/var\/tmp \u6743\u9650<\/h4>\n<p>\u653b\u51fb\u8005\u7ecf\u5e38\u5229\u7528 \/tmp \u548c \/var\/tmp \u5199\u5165\u540e\u95e8\u6587\u4ef6\u3002\u5e94\u8be5\u5c06\u8fd9\u4e9b\u76ee\u5f55\u8bbe\u7f6e\u4e3a noexec\u3001nosuid\u3001nodev&#xff1a;<\/p>\n<p># \u67e5\u770b\u5f53\u524d \/tmp \u6302\u8f7d\u9009\u9879<br \/>\nmount | grep \/tmp<\/p>\n<p># \u5982\u679c \/tmp \u662f\u72ec\u7acb\u5206\u533a&#xff0c;\u6dfb\u52a0\u5b89\u5168\u6302\u8f7d\u9009\u9879<br \/>\n# \u7f16\u8f91 \/etc\/fstab<br \/>\nUUID&#061;xxxx-xxxx-xxxx \/tmp ext4 defaults,noexec,nosuid,nodev 0 0<\/p>\n<p># \u5982\u679c \/tmp \u4e0d\u662f\u72ec\u7acb\u5206\u533a&#xff08;\u5927\u591a\u6570\u4e91\u670d\u52a1\u5668\u9ed8\u8ba4&#xff09;&#xff0c;\u521b\u5efa\u4e00\u4e2a\u72ec\u7acb\u7684 \/tmp \u5206\u533a<br \/>\n# \u5148\u521b\u5efa 2G \u5927\u5c0f\u7684\u955c\u50cf\u6587\u4ef6<br \/>\ndd\u00a0if&#061;\/dev\/zero of&#061;\/var\/tmp.mount bs&#061;1M count&#061;2048<br \/>\nmkfs.ext4 \/var\/tmp.mount<\/p>\n<p># \u5907\u4efd\u539f \/tmp \u5185\u5bb9<br \/>\ncp -a \/tmp \/tmp.bak<\/p>\n<p># \u6302\u8f7d\u65b0\u5206\u533a<br \/>\nmount &#8211;bind\u00a0\/var\/tmp.mount \/tmp<\/p>\n<p># \u6062\u590d\u5185\u5bb9<br \/>\ncp -a \/tmp.bak\/* \/tmp\/<\/p>\n<p># \u8bbe\u7f6e\u6743\u9650<br \/>\nchmod 1777 \/tmp<\/p>\n<p># \u6dfb\u52a0\u5230 \/etc\/fstab \u786e\u4fdd\u91cd\u542f\u540e\u751f\u6548<br \/>\necho&#034;\/var\/tmp.mount \/tmp ext4 defaults,bind,noexec,nosuid,nodev 0 0&#034;\u00a0&gt;&gt; \/etc\/fstab<\/p>\n<h4>5.2 \u9650\u5236\u7cfb\u7edf\u5185\u6838\u6a21\u5757\u52a0\u8f7d<\/h4>\n<p>\u9632\u6b62\u653b\u51fb\u8005\u52a0\u8f7d\u6076\u610f\u5185\u6838\u6a21\u5757&#xff1a;<\/p>\n<p># \u7981\u7528\u6a21\u5757\u52a0\u8f7d\u80fd\u529b<br \/>\necho&#034;install usb-storage \/bin\/true&#034;\u00a0&gt;&gt; \/etc\/modprobe.d\/no-usb.conf<br \/>\necho&#034;install bluetooth \/bin\/true&#034;\u00a0&gt;&gt; \/etc\/modprobe.d\/no-usb.conf<br \/>\necho&#034;install freevxfs \/bin\/true&#034;\u00a0&gt;&gt; \/etc\/modprobe.d\/no-usb.conf<br \/>\necho&#034;install jffs2 \/bin\/true&#034;\u00a0&gt;&gt; \/etc\/modprobe.d\/no-usb.conf<br \/>\necho&#034;install hfs \/bin\/true&#034;\u00a0&gt;&gt; \/etc\/modprobe.d\/no-usb.conf<br \/>\necho&#034;install hfsplus \/bin\/true&#034;\u00a0&gt;&gt; \/etc\/modprobe.d\/no-usb.conf<br \/>\necho&#034;install squashfs \/bin\/true&#034;\u00a0&gt;&gt; \/etc\/modprobe.d\/no-usb.conf<br \/>\necho&#034;install udf \/bin\/true&#034;\u00a0&gt;&gt; \/etc\/modprobe.d\/no-usb.conf<br \/>\necho&#034;install dccp \/bin\/true&#034;\u00a0&gt;&gt; \/etc\/modprobe.d\/no-usb.conf<\/p>\n<h4>5.3 \u8bbe\u7f6e umask \u9ed8\u8ba4\u503c<\/h4>\n<p>\u6536\u7d27\u7528\u6237\u7684\u9ed8\u8ba4\u6587\u4ef6\u521b\u5efa\u6743\u9650&#xff1a;<\/p>\n<p># \/etc\/profile \u4e2d\u8bbe\u7f6e\u66f4\u4e25\u683c\u7684 umask<br \/>\n# \u627e\u5230 umask \u90a3\u884c&#xff0c;\u6539\u4e3a&#xff1a;<br \/>\numask\u00a00027 \u00a0# \u9ed8\u8ba4\u521b\u5efa\u6587\u4ef6 640&#xff0c;\u76ee\u5f55 750<\/p>\n<p># \/etc\/csh.cshrc \u4e2d\u4e5f\u4fee\u6539&#xff1a;<br \/>\nset\u00a0umask\u00a00027<\/p>\n<h4>5.4 \u5173\u952e\u6587\u4ef6\u6743\u9650\u68c0\u67e5<\/h4>\n<p># \u68c0\u67e5\u5173\u952e\u6587\u4ef6\u6743\u9650<br \/>\nchmod 644 \/etc\/passwd<br \/>\nchmod 000 \/etc\/shadow \u00a0 \u00a0 \u00a0# shadow \u6587\u4ef6\u53ea\u6709 root \u53ef\u8bfb\u5199<br \/>\nchmod 644 \/etc\/group<br \/>\nchmod 640 \/etc\/gshadow<br \/>\nchmod 600 \/etc\/crontab<br \/>\nchmod 600 \/etc\/anacrontab<br \/>\nchmod 700 \/var\/spool\/cron<br \/>\nchmod 600 \/etc\/ssh\/sshd_config<br \/>\nchmod 644 \/etc\/hosts.allow<br \/>\nchmod 644 \/etc\/hosts.deny<br \/>\nchmod 600 \/etc\/rsyslog.conf<br \/>\nchmod 700 \/etc\/cron.d<br \/>\nchmod 700 \/etc\/cron.daily<br \/>\nchmod 700 \/etc\/cron.hourly<br \/>\nchmod 700 \/etc\/cron.monthly<br \/>\nchmod 700 \/etc\/cron.weekly<\/p>\n<h3>6. \u7f51\u7edc\u5c42\u52a0\u56fa<\/h3>\n<h4>6.1 \u9632\u706b\u5899\u57fa\u7840\u914d\u7f6e<\/h4>\n<p>\u4f7f\u7528 iptables \u6216 firewalld \u9650\u5236\u5165\u7ad9\u6d41\u91cf\u3002\u539f\u5219&#xff1a;\u9ed8\u8ba4\u62d2\u7edd\u6240\u6709&#xff0c;\u53ea\u653e\u884c\u5fc5\u8981\u7684\u7aef\u53e3\u3002<\/p>\n<p>\u4f7f\u7528 firewalld&#xff08;CentOS\/RHEL 7&#043;&#xff09;&#xff1a;<\/p>\n<p># \u67e5\u770b\u5f53\u524d\u89c4\u5219<br \/>\nfirewall-cmd &#8211;list-all<br \/>\nfirewall-cmd &#8211;list-ports<br \/>\nfirewall-cmd &#8211;list-services<\/p>\n<p># \u653e\u884c\u5fc5\u8981\u7aef\u53e3<br \/>\nfirewall-cmd &#8211;permanent &#8211;add-port&#061;22022\/tcp \u00a0 \u00a0# SSH<br \/>\nfirewall-cmd &#8211;permanent &#8211;add-port&#061;80\/tcp \u00a0 \u00a0 \u00a0 \u00a0# HTTP<br \/>\nfirewall-cmd &#8211;permanent &#8211;add-port&#061;443\/tcp \u00a0 \u00a0 \u00a0\u00a0# HTTPS<br \/>\nfirewall-cmd &#8211;permanent &#8211;add-port&#061;3306\/tcp \u00a0 \u00a0 \u00a0# MySQL&#xff08;\u5982\u679c\u9700\u8981\u4ece\u5185\u7f51\u76f4\u63a5\u8bbf\u95ee&#xff09;<br \/>\nfirewall-cmd &#8211;permanent &#8211;add-port&#061;6379\/tcp \u00a0 \u00a0 \u00a0# Redis&#xff08;\u4ec5\u5185\u7f51&#xff09;<\/p>\n<p># \u653e\u884c\u5fc5\u8981\u670d\u52a1<br \/>\nfirewall-cmd &#8211;permanent &#8211;add-service&#061;http<br \/>\nfirewall-cmd &#8211;permanent &#8211;add-service&#061;https<br \/>\nfirewall-cmd &#8211;permanent &#8211;add-service&#061;ssh<\/p>\n<p># \u7981\u6b62 Ping&#xff08;\u9632\u626b\u63cf&#xff09;<br \/>\nfirewall-cmd &#8211;permanent &#8211;add-icmp-block&#061;echo-request<\/p>\n<p># \u9ed8\u8ba4\u62d2\u7edd\u6240\u6709\u5165\u7ad9<br \/>\nfirewall-cmd &#8211;set-default-zone&#061;drop<\/p>\n<p># \u53ea\u5141\u8bb8\u7279\u5b9a\u6765\u6e90 IP \u8bbf\u95ee SSH<br \/>\nfirewall-cmd &#8211;permanent &#8211;zone&#061;trusted &#8211;add-source&#061;10.0.0.0\/8<br \/>\nfirewall-cmd &#8211;permanent &#8211;zone&#061;trusted &#8211;add-source&#061;192.168.0.0\/16<br \/>\nfirewall-cmd &#8211;permanent &#8211;add-rich-rule&#061;&#039;rule family&#061;&#034;ipv4&#034; source address&#061;&#034;your_office_ip\/32&#034; port port&#061;&#034;22022&#034; protocol&#061;&#034;tcp&#034; accept&#039;<\/p>\n<p># \u91cd\u8f7d\u9632\u706b\u5899<br \/>\nfirewall-cmd &#8211;reload<\/p>\n<p># \u67e5\u770b\u751f\u6548\u89c4\u5219<br \/>\nfirewall-cmd &#8211;list-all<\/p>\n<p>\u4f7f\u7528 iptables&#xff08;Ubuntu\/Debian \u6216 CentOS\/RHEL 6&#xff09;&#xff1a;<\/p>\n<p># \u4fdd\u5b58\u73b0\u6709\u89c4\u5219<br \/>\niptables-save &gt; \/opt\/iptables-backup-$(date &#043;%Y%m%d).rules<\/p>\n<p># \u7f16\u5199\u89c4\u5219\u811a\u672c<br \/>\ncat &gt; \/opt\/iptables-rules.sh &lt;&lt;\u00a0&#039;EOF&#039;<br \/>\n#!\/bin\/bash<br \/>\n# \u6e05\u7a7a\u73b0\u6709\u89c4\u5219<br \/>\niptables -F<br \/>\niptables -X<br \/>\niptables -t nat -F<br \/>\niptables -t nat -X<\/p>\n<p># \u9ed8\u8ba4\u62d2\u7edd\u6240\u6709\u5165\u7ad9<br \/>\niptables -P INPUT DROP<br \/>\niptables -P FORWARD DROP<br \/>\niptables -P OUTPUT ACCEPT<\/p>\n<p># \u5141\u8bb8\u672c\u5730\u56de\u73af<br \/>\niptables -A INPUT -i lo -j ACCEPT<br \/>\niptables -A OUTPUT -o lo -j ACCEPT<\/p>\n<p># \u5141\u8bb8\u5df2\u5efa\u7acb\u8fde\u63a5\u7684\u5305<br \/>\niptables -A INPUT -m state &#8211;state ESTABLISHED,RELATED -j ACCEPT<\/p>\n<p># \u5141\u8bb8 SSH&#xff08;\u6539\u6210\u4f60\u7684\u7aef\u53e3&#xff09;<br \/>\niptables -A INPUT -p tcp &#8211;dport 22022 -j ACCEPT<\/p>\n<p># \u5141\u8bb8 HTTP\/HTTPS<br \/>\niptables -A INPUT -p tcp &#8211;dport 80 -j ACCEPT<br \/>\niptables -A INPUT -p tcp &#8211;dport 443 -j ACCEPT<\/p>\n<p># \u5141\u8bb8 Ping<br \/>\niptables -A INPUT -p icmp &#8211;icmp-type\u00a0echo-request -j ACCEPT<\/p>\n<p># \u5141\u8bb8\u6765\u81ea\u5185\u7f51\u7684\u8fde\u63a5<br \/>\niptables -A INPUT -s 10.0.0.0\/8 -j ACCEPT<br \/>\niptables -A INPUT -s 192.168.0.0\/16 -j ACCEPT<\/p>\n<p># \u8bb0\u5f55\u88ab\u62d2\u7edd\u7684\u5305&#xff08;\u53ef\u9009&#xff0c;\u65b9\u4fbf\u6392\u67e5&#xff09;<br \/>\niptables -A INPUT -m\u00a0limit\u00a0&#8211;limit\u00a05\/min -j LOG &#8211;log-prefix\u00a0&#034;iptables DROP: &#034;\u00a0&#8211;log-level 4<\/p>\n<p># \u4fdd\u5b58\u89c4\u5219<br \/>\niptables-save &gt; \/etc\/iptables\/rules.v4<br \/>\nEOF<\/p>\n<p>chmod &#043;x \/opt\/iptables-rules.sh<br \/>\n\/opt\/iptables-rules.sh<\/p>\n<p># \u67e5\u770b\u89c4\u5219<br \/>\niptables -L -n -v<\/p>\n<h4>6.2 \u5185\u6838\u7f51\u7edc\u53c2\u6570\u52a0\u56fa<\/h4>\n<p>\u4fee\u6539\u00a0\/etc\/sysctl.conf&#xff0c;\u6536\u7d27\u7f51\u7edc\u5c42\u9762\u7684\u5b89\u5168\u53c2\u6570&#xff1a;<\/p>\n<p># \/etc\/sysctl.conf \u6dfb\u52a0\u6216\u4fee\u6539\u4ee5\u4e0b\u5185\u5bb9<\/p>\n<p># \u5173\u95ed IP \u8f6c\u53d1&#xff08;\u9664\u975e\u670d\u52a1\u5668\u505a\u8def\u7531\u5668&#xff09;<br \/>\nnet.ipv4.ip_forward &#061; 0<\/p>\n<p># \u5173\u95ed\u6570\u636e\u5305\u8f6c\u53d1&#xff08;\u9632\u6b62\u670d\u52a1\u5668\u6210\u4e3a\u8def\u7531\u8df3\u677f&#xff09;<br \/>\nnet.ipv4.conf.all.forwarding &#061; 0<br \/>\nnet.ipv4.conf.default.forwarding &#061; 0<\/p>\n<p># \u7981\u7528\u6e90\u8def\u7531\u5305&#xff08;\u9632\u6b62 IP \u4f2a\u88c5\u653b\u51fb&#xff09;<br \/>\nnet.ipv4.conf.all.accept_source_route &#061; 0<br \/>\nnet.ipv4.conf.default.accept_source_route &#061; 0<\/p>\n<p># \u5173\u95ed ICMP \u91cd\u5b9a\u5411<br \/>\nnet.ipv4.conf.all.accept_redirects &#061; 0<br \/>\nnet.ipv4.conf.default.accept_redirects &#061; 0<br \/>\nnet.ipv6.conf.all.accept_redirects &#061; 0<br \/>\nnet.ipv6.conf.default.accept_redirects &#061; 0<\/p>\n<p># \u5f00\u542f SYN Flood \u9632\u62a4<br \/>\nnet.ipv4.tcp_syncookies &#061; 1<br \/>\nnet.ipv4.tcp_syn_retries &#061; 2<br \/>\nnet.ipv4.tcp_synack_retries &#061; 2<br \/>\nnet.ipv4.tcp_max_syn_backlog &#061; 4096<\/p>\n<p># \u7981\u6b62 ICMP Ping \u5e7f\u64ad<br \/>\nnet.ipv4.icmp_echo_ignore_broadcasts &#061; 1<\/p>\n<p># \u5ffd\u7565 ICMP Ping&#xff08;\u53ef\u9009&#xff0c;\u5f71\u54cd\u76d1\u63a7\u63a2\u6d3b&#xff09;<br \/>\nnet.ipv4.icmp_echo_ignore_all &#061; 0 \u00a0# \u5efa\u8bae\u4fdd\u6301 0&#xff0c;\u65b9\u4fbf\u81ea\u5df1\u76d1\u63a7<\/p>\n<p># \u7981\u6b62\u8def\u7531\u8bb0\u5f55&#xff08; traceroute \u4f7f\u7528&#xff09;<br \/>\nnet.ipv4.conf.all.log_martians &#061; 1<br \/>\nnet.ipv4.conf.default.log_martians &#061; 1<\/p>\n<p># TIME_WAIT \u5feb\u901f\u56de\u6536<br \/>\nnet.ipv4.tcp_fin_timeout &#061; 30<br \/>\nnet.ipv4.tcp_tw_reuse &#061; 1<\/p>\n<p># \u6700\u5927\u6587\u4ef6\u63cf\u8ff0\u7b26<br \/>\nfs.file-max &#061; 6553600<\/p>\n<p># \u5e94\u7528\u914d\u7f6e<br \/>\nsysctl -p<\/p>\n<h4>6.3 \u9650\u5236\u6838\u5fc3\u6587\u4ef6\u8bbf\u95ee<\/h4>\n<p># \u7981\u6b62\u901a\u8fc7 ICMP \u8def\u7531\u8ffd\u8e2a&#xff08;\u9632\u6b62\u653b\u51fb\u8005\u63a2\u6d4b\u7f51\u7edc\u62d3\u6251&#xff09;<br \/>\necho\u00a01 &gt; \/proc\/sys\/net\/ipv4\/conf\/all\/accept_source_route<br \/>\n# \u4e0a\u9762\u5df2\u7ecf\u5728 sysctl.conf \u4e2d\u8bbe\u7f6e<\/p>\n<p># \u7981\u6b62\u4fee\u6539\u8def\u7531\u8868<br \/>\necho\u00a00 &gt; \/proc\/sys\/net\/ipv4\/conf\/all\/accept_redirects<br \/>\necho\u00a00 &gt; \/proc\/sys\/net\/ipv6\/conf\/all\/accept_redirects<\/p>\n<h3>7. \u670d\u52a1\u5b89\u5168<\/h3>\n<h4>7.1 \u7981\u7528\u4e0d\u5fc5\u8981\u7684\u670d\u52a1<\/h4>\n<p>\u670d\u52a1\u5668\u4e0a\u4e0d\u9700\u8981\u7684\u670d\u52a1\u8d8a\u591a&#xff0c;\u653b\u51fb\u9762\u8d8a\u5927\u3002\u68c0\u67e5\u5e76\u7981\u7528\u4e0d\u9700\u8981\u7684\u670d\u52a1&#xff1a;<\/p>\n<p># \u67e5\u770b\u6240\u6709\u5f00\u673a\u81ea\u542f\u670d\u52a1<br \/>\nsystemctl list-unit-files &#8211;type&#061;service &#8211;state&#061;enabled<\/p>\n<p># \u67e5\u770b\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1<br \/>\nsystemctl &#8211;type&#061;service &#8211;state&#061;running<\/p>\n<p># \u5e38\u89c1\u9700\u8981\u68c0\u67e5\u548c\u7981\u7528\u7684\u670d\u52a1&#xff08;\u6309\u9700\u8c03\u6574&#xff09;<br \/>\n# telnet-server&#xff1a;\u660e\u6587\u4f20\u8f93&#xff0c;\u5e94\u7981\u7528<br \/>\nsystemctl\u00a0disable\u00a0telnet.socket 2&gt;\/dev\/null<br \/>\nsystemctl stop telnet.socket 2&gt;\/dev\/null<\/p>\n<p># vsftpd&#xff1a;\u5982\u679c\u4e0d\u7528 FTP \u5c31\u7981\u7528<br \/>\nsystemctl\u00a0disable\u00a0vsftpd 2&gt;\/dev\/null<\/p>\n<p># sendmail&#xff1a;\u90ae\u4ef6\u670d\u52a1&#xff0c;\u5982\u4e0d\u9700\u8981\u5c31\u7981\u7528<br \/>\nsystemctl\u00a0disable\u00a0sendmail 2&gt;\/dev\/null<\/p>\n<p># postfix&#xff1a;\u5982\u679c\u4e0d\u7528\u90ae\u4ef6\u5c31\u7981\u7528<br \/>\nsystemctl\u00a0disable\u00a0postfix 2&gt;\/dev\/null<\/p>\n<p># cups&#xff1a;\u6253\u5370\u670d\u52a1&#xff0c;\u4e91\u670d\u52a1\u5668\u4e0d\u9700\u8981<br \/>\nsystemctl\u00a0disable\u00a0cups 2&gt;\/dev\/null<\/p>\n<p># dovecot&#xff1a;\u5982\u679c\u4e0d\u7528 IMAP\/POP3 \u5c31\u7981\u7528<br \/>\nsystemctl\u00a0disable\u00a0dovecot 2&gt;\/dev\/null<\/p>\n<p># nfslock\/nfs&#xff1a;\u5982\u679c\u4e0d\u505a NFS \u6587\u4ef6\u5171\u4eab\u5c31\u7981\u7528<br \/>\nsystemctl\u00a0disable\u00a0nfs-lock 2&gt;\/dev\/null<br \/>\nsystemctl\u00a0disable\u00a0nfs 2&gt;\/dev\/null<\/p>\n<p># rpcbind&#xff1a;NFS \u4f9d\u8d56\u7684\u670d\u52a1<br \/>\nsystemctl\u00a0disable\u00a0rpcbind 2&gt;\/dev\/null<\/p>\n<p># bluetooth&#xff1a;\u4e91\u670d\u52a1\u5668\u4e0d\u9700\u8981\u84dd\u7259<br \/>\nsystemctl\u00a0disable\u00a0bluetooth 2&gt;\/dev\/null<br \/>\nsystemctl stop bluetooth 2&gt;\/dev\/null<\/p>\n<p># \u786e\u8ba4\u6ca1\u6709\u4e0d\u9700\u8981\u7684\u670d\u52a1\u5728\u8fd0\u884c<br \/>\nsystemctl &#8211;type&#061;service &#8211;state&#061;running | grep -v -E\u00a0&#034;(sshd|cron|rsyslog|systemd|dbus|network|polkit|irqbalance|sssd)&#034;<\/p>\n<h4>7.2 \u67e5\u770b\u76d1\u542c\u7aef\u53e3<\/h4>\n<p>\u786e\u4fdd\u670d\u52a1\u5668\u4e0a\u53ea\u6709\u4f60\u77e5\u9053\u7684\u7aef\u53e3\u5728\u76d1\u542c&#xff1a;<\/p>\n<p># \u67e5\u770b\u6240\u6709\u76d1\u542c\u7aef\u53e3<br \/>\nss -tulnp<br \/>\n# \u6216<br \/>\nnetstat -tulnp<\/p>\n<p># \u7279\u522b\u5173\u6ce8\u4ee5\u4e0b\u51e0\u70b9&#xff1a;<br \/>\n# 1. \u662f\u5426\u6709\u4e0d\u660e\u670d\u52a1\u76d1\u542c\u5728\u9ad8\u5371\u7aef\u53e3&#xff08;\u5982 4444\u30015555 \u662f Metasploit \u5e38\u7528\u7aef\u53e3&#xff09;<br \/>\n# 2. \u662f\u5426\u6709\u670d\u52a1\u76d1\u542c\u5728 0.0.0.0&#xff08;\u5e94\u8be5\u5927\u90e8\u5206\u670d\u52a1\u53ea\u76d1\u542c 127.0.0.1 \u6216\u5185\u7f51 IP&#xff09;<br \/>\n# 3. \u662f\u5426\u6709\u670d\u52a1\u76d1\u542c\u5728\u516c\u7f51 IP \u4f46\u4e0d\u5e94\u8be5\u66b4\u9732&#xff08;\u5982\u6570\u636e\u5e93\u3001Redis&#xff09;<\/p>\n<p># \u793a\u4f8b&#xff1a;\u68c0\u67e5\u975e\u9884\u671f\u7684\u76d1\u542c<br \/>\nss -tulnp | grep -v -E\u00a0&#034;(22|80|443|22022)&#034;<\/p>\n<h4>7.3 \u9690\u85cf\u670d\u52a1\u7248\u672c\u4fe1\u606f<\/h4>\n<p>\u5f88\u591a\u670d\u52a1\u4f1a\u5728 banner \u4e2d\u663e\u793a\u7248\u672c\u53f7&#xff0c;\u653b\u51fb\u8005\u5229\u7528\u7248\u672c\u4fe1\u606f\u67e5\u627e\u5bf9\u5e94\u6f0f\u6d1e&#xff1a;<\/p>\n<p># Nginx \u7248\u672c\u9690\u85cf&#xff08;\u5728 nginx.conf \u4e2d&#xff09;<br \/>\nserver_tokens off;<\/p>\n<p># MySQL \u7248\u672c\u9690\u85cf<br \/>\n# MySQL 5.7&#043;: \u5728 my.cnf [mysqld] \u4e2d<br \/>\n# MySQL 8.0&#043;: \u4e0d\u9700\u8981\u5355\u72ec\u914d\u7f6e&#xff0c;\u9ed8\u8ba4\u4e0d\u663e\u793a\u7248\u672c<\/p>\n<p># SSH \u7248\u672c&#xff08;\u5728 \/etc\/ssh\/sshd_config \u4e2d&#xff09;<br \/>\n# SSH \u9ed8\u8ba4 banner \u65e0\u6cd5\u5b8c\u5168\u9690\u85cf&#xff0c;\u4f46\u53ef\u4ee5\u964d\u7ea7\u653b\u51fb\u8005\u4fe1\u5fc3<br \/>\n# \u7f16\u8f91 \/etc\/ssh\/sshd_config<br \/>\n# \u627e\u5230\u00a0#Banner\u00a0none&#xff0c;\u6539\u4e3a&#xff1a;<br \/>\n# Banner \/etc\/ssh\/banner<br \/>\n# \u521b\u5efa\u81ea\u5b9a\u4e49 banner \u6587\u4ef6<br \/>\necho&#034;Welcome to Secure Server&#034;\u00a0&gt; \/etc\/ssh\/banner<\/p>\n<p># Redis \u9ed8\u8ba4\u76d1\u542c 6379&#xff0c;\u4e14\u65e0\u8ba4\u8bc1<br \/>\n# \u5982\u679c\u5fc5\u987b\u66b4\u9732\u5728\u5916\u7f51&#xff0c;\u5fc5\u987b\u8bbe\u7f6e\u5bc6\u7801<br \/>\n# \/etc\/redis\/redis.conf<br \/>\n# requirepass your_strong_password_here<br \/>\n# bind 127.0.0.1<br \/>\n# rename-command FLUSHDB &#034;&#034; \u00a0 # \u7981\u7528 FLUSHDB \u547d\u4ee4<br \/>\n# rename-command FLUSHALL &#034;&#034; \u00a0 # \u7981\u7528 FLUSHALL \u547d\u4ee4<br \/>\n# rename-command KEYS &#034;&#034; \u00a0 \u00a0 \u00a0 # \u7981\u6b62 KEYS \u547d\u4ee4&#xff08;\u6216\u7528 SCAN \u66ff\u4ee3&#xff09;<\/p>\n<h3>8. SELinux\/AppArmor \u52a0\u56fa<\/h3>\n<h4>8.1 CentOS\/RHEL&#xff1a;\u542f\u7528 SELinux<\/h4>\n<p>SELinux \u662f\u5185\u6838\u7ea7\u7684\u8bbf\u95ee\u63a7\u5236\u7cfb\u7edf&#xff0c;\u80fd\u9650\u5236\u88ab\u5165\u4fb5\u540e\u7684\u6a2a\u5411\u79fb\u52a8&#xff1a;<\/p>\n<p># \u68c0\u67e5 SELinux \u72b6\u6001<br \/>\ngetenforce<br \/>\nsestatus<\/p>\n<p># \u5982\u679c\u662f Permissive&#xff0c;\u6539\u4e3a Enforcing<br \/>\n# \u7f16\u8f91 \/etc\/selinux\/config<br \/>\nSELINUX&#061;enforcing<br \/>\nSELINUXTYPE&#061;targeted<\/p>\n<p># \u4e34\u65f6\u751f\u6548<br \/>\nsetenforce 1<\/p>\n<p># SELinux \u5e38\u7528\u7ba1\u7406\u547d\u4ee4<br \/>\n# \u67e5\u770b\u6587\u4ef6\u5b89\u5168\u4e0a\u4e0b\u6587<br \/>\nls -Z \/var\/www\/html<br \/>\nps auxZ | grep nginx<\/p>\n<p># \u4fee\u6539\u76ee\u5f55\u5b89\u5168\u4e0a\u4e0b\u6587&#xff08;Web \u76ee\u5f55\u8fc1\u79fb\u540e\u5e38\u7528&#xff09;<br \/>\nsemanage fcontext -a -t httpd_sys_content_t\u00a0&#034;\/var\/www(\/.*)?&#034;<br \/>\nrestorecon -Rv \/var\/www<\/p>\n<p># \u5141\u8bb8\u670d\u52a1\u4f7f\u7528\u975e\u6807\u51c6\u7aef\u53e3<br \/>\nsemanage port -a -t http_port_t -p tcp 8080<\/p>\n<p>\u98ce\u9669\u63d0\u9192&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5f00\u542f SELinux \u524d\u8981\u786e\u4fdd\u719f\u6089\u5e38\u89c1\u5e94\u7528\u7684\u914d\u7f6e&#xff0c;\u5426\u5219\u4f1a\u5bfc\u81f4\u670d\u52a1\u542f\u52a8\u5931\u8d25\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u4e1a\u52a1\u5e94\u7528\u5728 Permissive \u6a21\u5f0f\u4e0b\u8fd0\u884c\u6b63\u5e38\u518d\u5207\u6362\u5230 Enforcing\u3002<\/p>\n<\/li>\n<li>\n<p>\u9047\u5230\u6743\u9650\u95ee\u9898\u65f6&#xff0c;\u4f18\u5148\u7528\u00a0ausearch\u3001sealert\u00a0\u67e5\u770b SELinux \u62d2\u7edd\u65e5\u5fd7&#xff0c;\u800c\u4e0d\u662f\u76f4\u63a5\u964d\u7ea7\u5230 Permissive\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>8.2 Ubuntu\/Debian&#xff1a;\u914d\u7f6e AppArmor<\/h4>\n<p># \u68c0\u67e5 AppArmor \u72b6\u6001<br \/>\naa-status<\/p>\n<p># \u67e5\u770b\u6240\u6709\u914d\u7f6e\u6587\u4ef6\u7684\u52a0\u8f7d\u72b6\u6001<br \/>\napparmor_status<\/p>\n<p># AppArmor \u914d\u7f6e\u6587\u4ef6\u5728 \/etc\/apparmor.d\/<br \/>\n# \u7981\u7528\u4e0d\u5fc5\u8981\u914d\u7f6e\u7684\u6fc0\u8fdb\u6a21\u5f0f&#xff08;\u5982\u679c\u786e\u8ba4\u67d0\u670d\u52a1\u4e0d\u9700\u8981\u7f51\u7edc\u8bbf\u95ee&#xff09;<br \/>\n# \u7f16\u8f91 \/etc\/apparmor.d\/usr.sbin.httpd \u6216\u5bf9\u5e94\u7684 Nginx \u914d\u7f6e\u6587\u4ef6<br \/>\n# \u9650\u5236\u7f51\u7edc\u8bbf\u95ee&#xff1a;<br \/>\n# network inet tcp,<br \/>\n# deny network inet6 tcp,<\/p>\n<h3>9. \u65e5\u5fd7\u5ba1\u8ba1<\/h3>\n<h4>9.1 \u914d\u7f6e\u65e5\u5fd7\u96c6\u4e2d\u6536\u96c6<\/h4>\n<p>\u670d\u52a1\u5668\u88ab\u9ed1\u540e&#xff0c;\u653b\u51fb\u8005\u7b2c\u4e00\u4ef6\u4e8b\u5f80\u5f80\u662f\u6e05\u7406\u65e5\u5fd7\u3002\u65e5\u5fd7\u5fc5\u987b\u96c6\u4e2d\u5230\u8fdc\u7a0b\u670d\u52a1\u5668&#xff1a;<\/p>\n<p># rsyslog \u5ba2\u6237\u7aef\u914d\u7f6e&#xff0c;\u5c06\u65e5\u5fd7\u53d1\u9001\u5230\u8fdc\u7a0b\u65e5\u5fd7\u670d\u52a1\u5668<br \/>\n# \/etc\/rsyslog.conf \u6dfb\u52a0&#xff1a;<br \/>\n*.* &#064;&#064;log-server.example.com:514<\/p>\n<p># \u6216\u4f7f\u7528 UDP&#xff08;\u6027\u80fd\u597d\u4f46\u53ef\u80fd\u4e22\u5305&#xff09;&#xff1a;<br \/>\n*.* &#064;log-server.example.com:514<\/p>\n<p># CentOS\/RHEL \u91cd\u542f rsyslog<br \/>\nsystemctl restart rsyslog<\/p>\n<p># Ubuntu\/Debian<br \/>\nsystemctl restart rsyslog<\/p>\n<h4>9.2 \u914d\u7f6e\u5ba1\u8ba1\u65e5\u5fd7<\/h4>\n<p>Linux \u5ba1\u8ba1\u5b88\u62a4\u8fdb\u7a0b&#xff08;auditd&#xff09;\u8bb0\u5f55\u7cfb\u7edf\u8c03\u7528&#xff0c;\u662f\u53d6\u8bc1\u7684\u91cd\u8981\u4f9d\u636e&#xff1a;<\/p>\n<p># \u5b89\u88c5 auditd<br \/>\nyum install -y audit \u00a0# CentOS\/RHEL<br \/>\napt install -y auditd \u00a0# Ubuntu\/Debian<\/p>\n<p># \u542f\u52a8\u5e76\u8bbe\u7f6e\u5f00\u673a\u81ea\u542f<br \/>\nsystemctl\u00a0enable\u00a0auditd<br \/>\nsystemctl start auditd<\/p>\n<p># \u914d\u7f6e\u5ba1\u8ba1\u89c4\u5219<br \/>\n# \/etc\/audit\/rules.d\/audit.rules \u6216 \/etc\/audit\/audit.rules<br \/>\n# \u8bb0\u5f55\u6240\u6709\u4fee\u6539 \/etc\/passwd\u3001\/etc\/shadow\u3001\/etc\/group \u7684\u64cd\u4f5c<br \/>\n-w \/etc\/passwd -p wa -k identity_changes<br \/>\n-w \/etc\/shadow -p wa -k identity_changes<br \/>\n-w \/etc\/group -p wa -k identity_changes<br \/>\n-w \/etc\/gshadow -p wa -k identity_changes<\/p>\n<p># \u8bb0\u5f55\u6240\u6709 sudo \u547d\u4ee4<br \/>\n-w \/usr\/bin\/sudo -p x -k privileged_commands<\/p>\n<p># \u8bb0\u5f55 SSH \u767b\u5f55\u4e8b\u4ef6<br \/>\n-w \/etc\/ssh\/sshd_config -p wa -k ssh_config_changes<br \/>\n-a always,exit\u00a0-F arch&#061;b64 -S sshd -F auid&gt;&#061;1000 -F auid!&#061;4294967295 -k sshd_login<\/p>\n<p># \u8bb0\u5f55\u7f51\u7edc\u914d\u7f6e\u53d8\u66f4<br \/>\n-w \/etc\/sysconfig\/network -p wa -k network_changes<br \/>\n-w \/etc\/sysconfig\/network-scripts\/ -p wa -k network_changes<\/p>\n<p># \u8bb0\u5f55\u654f\u611f\u6587\u4ef6\u7684\u6267\u884c<br \/>\n-a always,exit\u00a0-F arch&#061;b64 -S execve -F path&#061;\/usr\/bin\/wget -k network_download<br \/>\n-a always,exit\u00a0-F arch&#061;b64 -S execve -F path&#061;\/usr\/bin\/curl -k network_download<br \/>\n-a always,exit\u00a0-F arch&#061;b64 -S execve -F path&#061;\/usr\/bin\/python* -k interpreter_usage<br \/>\n-a always,exit\u00a0-F arch&#061;b64 -S execve -F path&#061;\/usr\/bin\/perl -k interpreter_usage<\/p>\n<p># \u4f7f\u89c4\u5219\u751f\u6548<br \/>\naugenrules &#8211;load<\/p>\n<p># \u67e5\u770b\u5ba1\u8ba1\u65e5\u5fd7<br \/>\nausearch -k identity_changes | head -20<br \/>\nausearch -k sshd_login | head -20<\/p>\n<p># \u67e5\u770b\u6700\u8fd1\u7684\u5ba1\u8ba1\u4e8b\u4ef6<br \/>\naureport &#8211;latest-events<br \/>\naureport &#8211;auth | head -30<\/p>\n<h4>9.3 \u65e5\u5fd7\u6587\u4ef6\u5b8c\u6574\u6027\u6821\u9a8c<\/h4>\n<p>\u653b\u51fb\u8005\u53ef\u80fd\u4fee\u6539\u65e5\u5fd7\u63a9\u76d6\u5165\u4fb5\u75d5\u8ff9\u3002\u4f7f\u7528 AIDE \u6216 Tripwire \u505a\u6587\u4ef6\u5b8c\u6574\u6027\u68c0\u67e5&#xff1a;<\/p>\n<p># \u5b89\u88c5 AIDE<br \/>\nyum install -y aide \u00a0# CentOS\/RHEL<br \/>\napt install -y aide \u00a0\u00a0# Ubuntu\/Debian<\/p>\n<p># \u521d\u59cb\u5316 AIDE \u6570\u636e\u5e93&#xff08;\u7b2c\u4e00\u6b21\u8fd0\u884c&#xff09;<br \/>\naide &#8211;init<\/p>\n<p># \u79fb\u52a8\u521d\u59cb\u6570\u636e\u5e93<br \/>\nmv \/var\/lib\/aide\/aide.db.new.gz \/var\/lib\/aide\/aide.db.gz<\/p>\n<p># \u5b9a\u671f\u68c0\u67e5&#xff08;\u624b\u52a8&#xff09;<br \/>\naide &#8211;check<\/p>\n<p># \u66f4\u65b0\u6570\u636e\u5e93&#xff08;\u5728\u786e\u8ba4\u7cfb\u7edf\u6b63\u5e38\u540e&#xff09;<br \/>\naide &#8211;update<br \/>\nmv \/var\/lib\/aide\/aide.db.new.gz \/var\/lib\/aide\/aide.db.gz<\/p>\n<p># \u6bcf\u5929\u81ea\u52a8\u68c0\u67e5&#xff08;\u52a0\u5165 crontab&#xff09;<br \/>\necho&#034;0 3 * * * \/usr\/sbin\/aide &#8211;check&#034;\u00a0&gt;&gt; \/etc\/crontab<\/p>\n<h3>10. Rootkit \u548c\u540e\u95e8\u68c0\u6d4b<\/h3>\n<h4>10.1 \u4f7f\u7528 rkhunter \u68c0\u67e5 Rootkit<\/h4>\n<p># \u5b89\u88c5 rkhunter<br \/>\nyum install -y rkhunter \u00a0# CentOS\/RHEL<br \/>\napt install -y rkhunter \u00a0# Ubuntu\/Debian<\/p>\n<p># \u66f4\u65b0\u7279\u5f81\u5e93<br \/>\nrkhunter &#8211;update<\/p>\n<p># \u6267\u884c\u68c0\u67e5<br \/>\nrkhunter &#8211;check &#8211;sk &#8211;rwo<\/p>\n<p># \u5173\u952e\u68c0\u67e5\u9879&#xff1a;<br \/>\n# &#8211; \u68c0\u67e5\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u9690\u85cf\u6587\u4ef6<br \/>\n# &#8211; \u68c0\u67e5\u5e38\u89c1\u7684 Rootkit \u7279\u5f81<br \/>\n# &#8211; \u68c0\u67e5\u53ef\u7591\u7684 LKM&#xff08;Loadable Kernel Module&#xff09;<br \/>\n# &#8211; \u68c0\u67e5\u7f51\u7edc\u8fde\u63a5<br \/>\n# &#8211; \u68c0\u67e5\u7cfb\u7edf\u547d\u4ee4\u662f\u5426\u88ab\u66ff\u6362<\/p>\n<h4>10.2 \u4f7f\u7528 chkrootkit \u68c0\u67e5<\/h4>\n<p># \u5b89\u88c5 chkrootkit<br \/>\nyum install -y chkrootkit \u00a0# CentOS\/RHEL<br \/>\napt install -y chkrootkit \u00a0# Ubuntu\/Debian<\/p>\n<p># \u8fd0\u884c\u68c0\u67e5<br \/>\nchkrootkit | grep -v -E\u00a0&#034;(Checking|not found|Nothing found|Not tested)&#034;<\/p>\n<p># \u67e5\u770b\u7f51\u7edc\u76f8\u5173<br \/>\nchkrootkit -r<\/p>\n<p># \u6ce8\u610f&#xff1a;\u6709\u4e9b\u5b89\u5168\u8f6f\u4ef6\u4f1a\u8bef\u62a5<br \/>\n# \u5982\u6709\u8bef\u62a5&#xff0c;\u67e5\u770b\u5177\u4f53\u547d\u4ee4\u662f\u5426\u88ab\u66ff\u6362<br \/>\nwhich\u00a0ls<br \/>\nrpm -qf \/bin\/ls<br \/>\nmd5sum \/bin\/ls<\/p>\n<h4>10.3 \u68c0\u67e5\u5f02\u5e38\u8fdb\u7a0b\u548c\u7f51\u7edc\u8fde\u63a5<\/h4>\n<p># \u67e5\u770b\u6240\u6709\u8fdb\u7a0b&#xff08;\u5305\u62ec\u9690\u85cf\u8fdb\u7a0b&#xff09;<br \/>\nps auxf<br \/>\nps -ef<\/p>\n<p># \u67e5\u770b\u7f51\u7edc\u8fde\u63a5\u548c\u5bf9\u5e94\u8fdb\u7a0b<br \/>\nss -tulnp<br \/>\nnetstat -antp<\/p>\n<p># \u68c0\u67e5\u662f\u5426\u6709\u8fdb\u7a0b\u76d1\u542c\u5f02\u5e38\u7aef\u53e3<br \/>\nss -tulnp | grep -v -E\u00a0&#034;(22|80|443|22022)&#034;<\/p>\n<p># \u68c0\u67e5\u662f\u5426\u6709\u5230\u5916\u7f51\u7684\u5f02\u5e38\u8fde\u63a5&#xff08;\u88ab\u63a7\u670d\u52a1\u5668\u4f1a\u5411\u5916\u53d1\u9001\u6570\u636e&#xff09;<br \/>\nss -tnp | grep -v -E\u00a0&#034;(10\\\\.|192\\\\.168\\\\.|172\\\\.(1[6-9]|2[0-9]|3[01])\\\\.)&#034;<\/p>\n<p># \u68c0\u67e5\u662f\u5426\u6709\u8fdb\u7a0b\u5728\u8fd0\u884c\u4f46 ps \u770b\u4e0d\u5230&#xff08;\u9ad8\u7ea7 Rootkit \u7279\u5f81&#xff09;<br \/>\n# \u5982\u679c ps \u548c \/proc \u91cc\u770b\u5230\u8fdb\u7a0b\u4f46 ss\/netstat \u770b\u4e0d\u5230\u76d1\u542c\u7aef\u53e3&#xff0c;\u8bf4\u660e\u53ef\u80fd\u662f\u540e\u95e8<br \/>\nfor\u00a0pid\u00a0in\u00a0$(ls \/proc | grep\u00a0&#039;^[0-9]&#039;);\u00a0do<br \/>\n\u00a0 \u00a0\u00a0if\u00a0[ -f \/proc\/$pid\/cmdline ];\u00a0then<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0\u00a0echo&#034;PID\u00a0$pid:\u00a0$(cat \/proc\/$pid\/cmdline | tr &#039;\\\\0&#039; &#039; &#039;)&#034;<br \/>\n\u00a0 \u00a0\u00a0fi<br \/>\ndone\u00a0| head -50<\/p>\n<p># \u68c0\u67e5 crontab \u662f\u5426\u6709\u53ef\u7591\u4efb\u52a1<br \/>\ncrontab -l<br \/>\ncat \/etc\/crontab<br \/>\nls -la \/etc\/cron.d\/<br \/>\nls -la \/var\/spool\/cron\/<br \/>\ncat \/etc\/cron.d\/* 2&gt;\/dev\/null<\/p>\n<h4>10.4 \u68c0\u67e5 SSH authorized_keys \u662f\u5426\u88ab\u7be1\u6539<\/h4>\n<p># \u67e5\u770b\u6240\u6709\u7528\u6237\u7684 SSH authorized_keys&#xff08;\u53ef\u80fd\u88ab\u6dfb\u52a0\u4e86\u653b\u51fb\u8005\u7684\u516c\u94a5&#xff09;<br \/>\nfor\u00a0user\u00a0in\u00a0$(cut -d: -f1 \/etc\/passwd);\u00a0do<br \/>\n\u00a0 \u00a0 keyfile&#061;&#034;\/home\/$user\/.ssh\/authorized_keys&#034;<br \/>\n\u00a0 \u00a0\u00a0if\u00a0[ -f\u00a0&#034;$keyfile&#034;\u00a0];\u00a0then<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0\u00a0echo&#034;&#061;&#061;&#061;\u00a0$user\u00a0authorized_keys &#061;&#061;&#061;&#034;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 cat\u00a0&#034;$keyfile&#034;<br \/>\n\u00a0 \u00a0\u00a0fi<br \/>\ndone<\/p>\n<p># \u68c0\u67e5 root \u7684 authorized_keys&#xff08;root \u76f4\u63a5\u767b\u5f55\u5df2\u88ab\u7981\u7528&#xff0c;\u4f46 keys \u672c\u8eab\u4e5f\u53ef\u80fd\u88ab\u7be1\u6539&#xff09;<br \/>\nif\u00a0[ -f \/root\/.ssh\/authorized_keys ];\u00a0then<br \/>\n\u00a0 \u00a0\u00a0echo&#034;&#061;&#061;&#061; root authorized_keys &#061;&#061;&#061;&#034;<br \/>\n\u00a0 \u00a0 cat \/root\/.ssh\/authorized_keys<br \/>\nfi<\/p>\n<p># \u68c0\u67e5 SSH \u767b\u5f55\u8bb0\u5f55&#xff08;\u770b\u662f\u5426\u6709\u5f02\u5e38\u767b\u5f55\u65f6\u95f4\/IP&#xff09;<br \/>\nlast | head -30<br \/>\nlastlog | grep -v\u00a0&#034;Never&#034;<\/p>\n<h3>11. \u5185\u6838\u53c2\u6570\u52a0\u56fa<\/h3>\n<h4>11.1 \u9650\u5236\u8fdb\u7a0b\u8d44\u6e90\u4f7f\u7528<\/h4>\n<p>\u9632\u6b62\u5355\u4e2a\u8fdb\u7a0b\u8017\u5c3d\u7cfb\u7edf\u8d44\u6e90\u5bfc\u81f4 DoS&#xff1a;<\/p>\n<p># \/etc\/security\/limits.conf \u6dfb\u52a0&#xff1a;<br \/>\n# \u9650\u5236\u6700\u5927\u8fdb\u7a0b\u6570<br \/>\n* \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 soft \u00a0 \u00a0nproc \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 4096<br \/>\n* \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 hard \u00a0 \u00a0nproc \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 8192<\/p>\n<p># \u9650\u5236\u6700\u5927\u6587\u4ef6\u63cf\u8ff0\u7b26<br \/>\n* \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 soft \u00a0 \u00a0nofile \u00a0 \u00a0 \u00a0 \u00a0 \u00a065536<br \/>\n* \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 hard \u00a0 \u00a0nofile \u00a0 \u00a0 \u00a0 \u00a0 \u00a065536<\/p>\n<p># \u9650\u5236 core dump \u5927\u5c0f&#xff08;\u9632\u6b62\u6cc4\u9732\u654f\u611f\u5185\u5b58\u6570\u636e&#xff09;<br \/>\n* \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 soft \u00a0 \u00a0core \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a00<br \/>\n* \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 hard \u00a0 \u00a0core \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a00<\/p>\n<p># \u9650\u5236\u666e\u901a\u7528\u6237\u53ef\u4ee5\u4f7f\u7528\u7684\u5185\u5b58<br \/>\n# \u8fd9\u4e2a\u9700\u8981\u6839\u636e\u5b9e\u9645\u5185\u5b58\u8c03\u6574<br \/>\n# &#064;student \u00a0 \u00a0 \u00a0 hard \u00a0 \u00a0memlock \u00a0 \u00a0 \u00a0 \u00a02097152<\/p>\n<h4>11.2 \u7981\u6b62 ICMP \u91cd\u5b9a\u5411<\/h4>\n<p># \u5728 \/etc\/sysctl.conf \u4e2d\u5df2\u7ecf\u914d\u7f6e<br \/>\n# \u518d\u6b21\u786e\u8ba4<br \/>\ngrep -E\u00a0&#034;icmp_(echo_ignore_all|accept_redirects)&#034;\u00a0\/etc\/sysctl.conf<\/p>\n<p># \u7acb\u5373\u751f\u6548<br \/>\nsysctl -p<\/p>\n<h4>11.3 \u7981\u7528\u4e0d\u5fc5\u8981\u7684\u6587\u4ef6\u7cfb\u7edf<\/h4>\n<p>\u51cf\u5c11\u5185\u6838\u652f\u6301\u7684\u653b\u51fb\u9762&#xff1a;<\/p>\n<p># \/etc\/modprobe.d\/disable-filesystems.conf<br \/>\ninstall cramfs \/bin\/true<br \/>\ninstall freevxfs \/bin\/true<br \/>\ninstall jffs2 \/bin\/true<br \/>\ninstall hfs \/bin\/true<br \/>\ninstall hfsplus \/bin\/true<br \/>\ninstall squashfs \/bin\/true<br \/>\ninstall udf \/bin\/true<br \/>\ninstall vfat \/bin\/true<\/p>\n<h3>12. \u8f6f\u4ef6\u66f4\u65b0\u4e0e\u6f0f\u6d1e\u7ba1\u7406<\/h3>\n<h4>12.1 \u914d\u7f6e\u81ea\u52a8\u5b89\u5168\u66f4\u65b0<\/h4>\n<p># CentOS\/RHEL&#xff1a;\u4f7f\u7528 yum-cron<br \/>\nyum install -y yum-cron<\/p>\n<p># \u7f16\u8f91 \/etc\/yum\/yum-cron.conf<br \/>\nupdate_cmd &#061; security<br \/>\nupdate_messages &#061; yes<br \/>\ndownload_updates &#061; yes<br \/>\napply_updates &#061; yes<\/p>\n<p>systemctl\u00a0enable\u00a0yum-cron<br \/>\nsystemctl start yum-cron<\/p>\n<p># Ubuntu\/Debian&#xff1a;\u4f7f\u7528 unattended-upgrades<br \/>\napt install -y unattended-upgrades<br \/>\ndpkg-reconfigure -plow unattended-upgrades<br \/>\n# \u9009\u62e9 &#034;Yes&#034; \u542f\u7528\u81ea\u52a8\u5b89\u5168\u66f4\u65b0<\/p>\n<p># \u67e5\u770b\u81ea\u52a8\u66f4\u65b0\u65e5\u5fd7<br \/>\ntail -50 \/var\/log\/yum.log \u00a0# CentOS<br \/>\ntail -50 \/var\/log\/unattended-upgrades\/ \u00a0# Ubuntu<\/p>\n<h4>12.2 \u5b9a\u671f\u6f0f\u6d1e\u626b\u63cf<\/h4>\n<p># \u5b89\u88c5 OpenVAS \u6216\u4f7f\u7528 yum\/cve-check&#xff08;CentOS&#xff09;<br \/>\nyum install -y yum-plugin-security<br \/>\nyum updateinfo list security<\/p>\n<p># Ubuntu<br \/>\napt install -y unattended-upgrades<br \/>\n\/usr\/lib\/update-notifier\/update-notifier.notify-matches-available-security-updates<\/p>\n<p># \u5982\u679c\u6709\u5546\u4e1a\u6f0f\u6d1e\u626b\u63cf\u5668&#xff08;Qualys\u3001Rapid7&#xff09;&#xff0c;\u5b9a\u671f\u626b\u63cf\u751f\u4ea7\u670d\u52a1\u5668<br \/>\n# \u626b\u63cf\u524d\u901a\u77e5\u76f8\u5173\u65b9&#xff0c;\u9009\u62e9\u7ef4\u62a4\u7a97\u53e3<\/p>\n<h4>12.3 \u5185\u6838\u5347\u7ea7<\/h4>\n<p>\u5185\u6838\u6f0f\u6d1e\u5371\u5bb3\u6781\u5927&#xff0c;\u4f46\u5347\u7ea7\u5185\u6838\u6709\u98ce\u9669&#xff08;\u53ef\u80fd\u5f71\u54cd\u9a71\u52a8\u3001\u4e1a\u52a1\u4f9d\u8d56&#xff09;&#xff1a;<\/p>\n<p># CentOS\/RHEL \u67e5\u770b\u53ef\u7528\u5185\u6838<br \/>\ngrub2-mkconfig -o \/boot\/grub2\/grub.cfg<br \/>\nawk -F\\\\&#039; &#039;\/menuentry\/ {print\u00a0$2}&#039; \/boot\/grub2\/grub.cfg<\/p>\n<p># \u5b89\u88c5\u6700\u65b0\u7248\u5185\u6838<br \/>\nyum update -y kernel<\/p>\n<p># \u91cd\u542f\u540e\u9009\u62e9\u65b0\u5185\u6838<br \/>\nreboot<\/p>\n<p># \u786e\u8ba4\u4f7f\u7528\u7684\u662f\u65b0\u5185\u6838<br \/>\nuname -r<\/p>\n<p># \u8bbe\u7f6e\u9ed8\u8ba4\u542f\u52a8\u9879&#xff08;\u9632\u6b62\u8bef\u56de\u6eda&#xff09;<br \/>\ngrub2-set-default &#034;CentOS Linux (6.14.1-1.el8.x86_64) 8 (Core)&#034;<br \/>\ngrub2-mkconfig -o \/boot\/grub2\/grub.cfg<\/p>\n<p>\u98ce\u9669\u63d0\u9192&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5185\u6838\u5347\u7ea7\u5fc5\u987b\u901a\u8fc7\u6d4b\u8bd5\u73af\u5883\u9a8c\u8bc1\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e91\u670d\u52a1\u5668\u5347\u7ea7\u5185\u6838\u524d\u786e\u4fdd\u6709\u4e91\u63a7\u5236\u53f0\u6551\u63f4\u65b9\u5f0f\u3002<\/p>\n<\/li>\n<li>\n<p>\u5347\u7ea7\u524d\u8bb0\u5f55\u5f53\u524d\u5185\u6838\u7248\u672c\u548c\u542f\u52a8\u9879&#xff0c;\u4fdd\u7559\u56de\u6eda\u80fd\u529b\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>13. \u76d1\u63a7\u4e0e\u544a\u8b66<\/h3>\n<h4>13.1 \u8d26\u6237\u53d8\u66f4\u76d1\u63a7<\/h4>\n<p># \u76d1\u63a7 \/etc\/passwd\u3001\/etc\/shadow\u3001\/etc\/group \u7684\u53d8\u66f4<br \/>\n# \u4f7f\u7528 auditd&#xff08;\u524d\u9762\u5df2\u914d\u7f6e&#xff09;\u8bb0\u5f55\u53d8\u66f4<br \/>\n# \u914d\u5408\u4ee5\u4e0b\u811a\u672c\u6bcf\u65e5\u6bd4\u5bf9<\/p>\n<p>cat &gt; \/opt\/check-accounts.sh &lt;&lt;\u00a0&#039;EOF&#039;<br \/>\n#!\/bin\/bash<br \/>\n# \u5bf9\u6bd4\u5f53\u65e5\u548c\u6628\u65e5\u7684\u8d26\u6237\u6570\u636e<\/p>\n<p>YESTERDAY&#061;$(date -d\u00a0&#034;yesterday&#034;\u00a0&#043;%Y%m%d)<br \/>\nTODAY&#061;$(date &#043;%Y%m%d)<br \/>\nBACKUP_DIR&#061;&#034;\/opt\/security-hardening-backup&#034;<\/p>\n<p>if\u00a0[ ! -f\u00a0&#034;$BACKUP_DIR\/passwd.bak&#034;\u00a0];\u00a0then<br \/>\n\u00a0 \u00a0\u00a0echo&#034;No baseline found&#034;<br \/>\n\u00a0 \u00a0\u00a0exit\u00a01<br \/>\nfi<\/p>\n<p>echo&#034;&#061;&#061;&#061; Checking for new users &#061;&#061;&#061;&#034;<br \/>\ndiff &lt;(sort \/opt\/security-hardening-backup\/passwd.bak | cut -d: -f1) \\\\<br \/>\n\u00a0 \u00a0 \u00a0&lt;(sort \/etc\/passwd | cut -d: -f1) | grep\u00a0&#034;^&gt;&#034;<\/p>\n<p>echo&#034;&#061;&#061;&#061; Checking for removed users &#061;&#061;&#061;&#034;<br \/>\ndiff &lt;(sort \/opt\/security-hardening-backup\/passwd.bak | cut -d: -f1) \\\\<br \/>\n\u00a0 \u00a0 \u00a0&lt;(sort \/etc\/passwd | cut -d: -f1) | grep\u00a0&#034;^&lt;&#034;<\/p>\n<p>echo&#034;&#061;&#061;&#061; Checking for users with changed shells &#061;&#061;&#061;&#034;<br \/>\ndiff &lt;(sort \/opt\/security-hardening-backup\/passwd.bak | awk -F:\u00a0&#039;{print $1&#034;:&#034;$7}&#039;) \\\\<br \/>\n\u00a0 \u00a0 \u00a0&lt;(sort \/etc\/passwd | awk -F:\u00a0&#039;{print $1&#034;:&#034;$7}&#039;) | grep\u00a0&#034;^&gt;&#034;<\/p>\n<p>echo&#034;&#061;&#061;&#061; Checking for UID 0 users &#061;&#061;&#061;&#034;<br \/>\nawk -F:\u00a0&#039;($3&#061;&#061;0) {print $1}&#039;\u00a0\/etc\/passwd<br \/>\nEOF<\/p>\n<p>chmod &#043;x \/opt\/check-accounts.sh<\/p>\n<p># \u52a0\u5165 crontab \u6bcf\u65e5\u68c0\u67e5<br \/>\necho&#034;0 6 * * * root \/opt\/check-accounts.sh&#034;\u00a0&gt;&gt; \/etc\/crontab<\/p>\n<h4>13.2 \u65b0\u589e\u7f51\u7edc\u8fde\u63a5\u76d1\u63a7<\/h4>\n<p># \u76d1\u63a7\u662f\u5426\u6709\u65b0\u589e\u76d1\u542c\u7aef\u53e3&#xff08;\u53ef\u80fd\u540e\u95e8\u76d1\u542c&#xff09;<br \/>\ncat &gt; \/opt\/check-ports.sh &lt;&lt;\u00a0&#039;EOF&#039;<br \/>\n#!\/bin\/bash<br \/>\nYESTERDAY_PORTS&#061;&#034;\/var\/tmp\/listening-ports-backup.txt&#034;<br \/>\nTODAY_PORTS&#061;&#034;\/var\/tmp\/listening-ports-$(date &#043;%Y%m%d).txt&#034;<\/p>\n<p>ss -tulnp &gt;\u00a0&#034;$TODAY_PORTS&#034;<\/p>\n<p>if\u00a0[ -f\u00a0&#034;$YESTERDAY_PORTS&#034;\u00a0];\u00a0then<br \/>\n\u00a0 \u00a0\u00a0echo&#034;&#061;&#061;&#061; NEW listening ports &#061;&#061;&#061;&#034;<br \/>\n\u00a0 \u00a0 diff\u00a0&#034;$YESTERDAY_PORTS&#034;&#034;$TODAY_PORTS&#034;\u00a0| grep\u00a0&#034;^&gt;&#034;\u00a0||\u00a0echo&#034;None&#034;<br \/>\n\u00a0 \u00a0\u00a0echo&#034;&#061;&#061;&#061; REMOVED listening ports &#061;&#061;&#061;&#034;<br \/>\n\u00a0 \u00a0 diff\u00a0&#034;$YESTERDAY_PORTS&#034;&#034;$TODAY_PORTS&#034;\u00a0| grep\u00a0&#034;^&lt;&#034;\u00a0||\u00a0echo&#034;None&#034;<br \/>\nfi<\/p>\n<p>cp\u00a0&#034;$TODAY_PORTS&#034;&#034;$YESTERDAY_PORTS&#034;<br \/>\nEOF<\/p>\n<p>chmod &#043;x \/opt\/check-ports.sh<\/p>\n<h4>13.3 Prometheus &#043; Alertmanager \u544a\u8b66\u4f53\u7cfb<\/h4>\n<p># node_exporter \u91c7\u96c6\u7cfb\u7edf\u6307\u6807<br \/>\n# \u5b89\u88c5 node_exporter<br \/>\nwget https:\/\/github.com\/prometheus\/node_exporter\/releases\/download\/v1.7.0\/node_exporter-1.7.0.linux-amd64.tar.gz<br \/>\ntar xvf node_exporter-1.7.0.linux-amd64.tar.gz<br \/>\nmv node_exporter-1.7.0.linux-amd64\/node_exporter \/usr\/local\/bin\/<\/p>\n<p># \u521b\u5efa systemd \u670d\u52a1&#xff08;\u542f\u7528 textfile collector \u7528\u4e8e\u81ea\u5b9a\u4e49\u6307\u6807&#xff09;<br \/>\ncat &gt; \/etc\/systemd\/system\/node_exporter.service &lt;&lt;\u00a0&#039;EOF&#039;<br \/>\n[Unit]<br \/>\nDescription&#061;Node Exporter<br \/>\nAfter&#061;network.target<\/p>\n<p>[Service]<br \/>\nExecStart&#061;\/usr\/local\/bin\/node_exporter &#8211;collector.textfile.directory&#061;\/var\/lib\/node_exporter\/textfile_collector<br \/>\nRestart&#061;on-failure<\/p>\n<p>[Install]<br \/>\nWantedBy&#061;multi-user.target<br \/>\nEOF<\/p>\n<p>systemctl daemon-reload<br \/>\nsystemctl\u00a0enable\u00a0node_exporter<br \/>\nsystemctl start node_exporter<\/p>\n<p># \u521b\u5efa\u81ea\u5b9a\u4e49\u6307\u6807\u91c7\u96c6\u811a\u672c&#xff0c;\u7edf\u8ba1\u76d1\u542c\u7aef\u53e3\u6570\u91cf<br \/>\n# \u901a\u8fc7 ss -tuln \u8f93\u51fa\u7edf\u8ba1\u5f53\u524d\u76d1\u542c TCP\/UDP \u7aef\u53e3\u6570&#xff0c;\u7528\u4e8e\u68c0\u6d4b\u88ab\u63a7\u540e\u65b0\u589e\u76d1\u542c\u7aef\u53e3<br \/>\nmkdir -p \/var\/lib\/node_exporter\/textfile_collector<br \/>\ncat &gt; \/usr\/local\/bin\/node_sock_listen.sh &lt;&lt;\u00a0&#039;SCRIPT&#039;<br \/>\n#!\/bin\/bash<br \/>\nOUTFILE&#061;&#034;\/var\/lib\/node_exporter\/textfile_collector\/node_sock_listen.prom&#034;<\/p>\n<p># \u7edf\u8ba1\u5f53\u524d\u76d1\u542c\u4e2d\u7684 TCP \u7aef\u53e3\u6570\u91cf&#xff08;\u6392\u9664\u56de\u73af\u548c\u76d1\u542c\u72b6\u6001\u4e3a\u7a7a\u7684\u884c&#xff09;<br \/>\nTCP_LISTEN&#061;$(ss -tuln | grep -c\u00a0&#034;LISTEN&#034;\u00a0||\u00a0echo\u00a00)<\/p>\n<p># \u7edf\u8ba1\u5f53\u524d\u76d1\u542c\u4e2d\u7684 UDP \u7aef\u53e3\u6570\u91cf<br \/>\nUDP_LISTEN&#061;$(ss -uuln | grep -c\u00a0&#034;UNCONN&#034;\u00a0||\u00a0echo\u00a00)<\/p>\n<p># \u8f93\u51fa Prometheus textfile \u683c\u5f0f<br \/>\ncat &gt;\u00a0&#034;${OUTFILE}.tmp&#034;\u00a0&lt;&lt; EOF<br \/>\n# HELP node_sock_listen_count Number of listening sockets by protocol<br \/>\n# TYPE node_sock_listen_count gauge<br \/>\nnode_sock_listen_count{protocol&#061;&#034;tcp&#034;}\u00a0${TCP_LISTEN}<br \/>\nnode_sock_listen_count{protocol&#061;&#034;udp&#034;}\u00a0${UDP_LISTEN}<br \/>\nEOF<br \/>\nmv\u00a0&#034;${OUTFILE}.tmp&#034;&#034;${OUTFILE}&#034;<br \/>\nSCRIPT<\/p>\n<p>chmod &#043;x \/usr\/local\/bin\/node_sock_listen.sh<\/p>\n<p># \u52a0\u5165 crontab&#xff0c;\u6bcf\u5206\u949f\u6267\u884c\u4e00\u6b21<br \/>\necho&#034;* * * * * root \/usr\/local\/bin\/node_sock_listen.sh&#034;\u00a0&gt;&gt; \/etc\/crontab<\/p>\n<p># \u624b\u52a8\u6267\u884c\u4e00\u6b21\u6d4b\u8bd5<br \/>\n\/usr\/local\/bin\/node_sock_listen.sh<br \/>\ncat \/var\/lib\/node_exporter\/textfile_collector\/node_sock_listen.prom<\/p>\n<p># \u5173\u952e\u544a\u8b66\u89c4\u5219&#xff08;Prometheus rule file&#xff09;<br \/>\n# \/etc\/prometheus\/rules.yml<br \/>\ngroups:<br \/>\n&#8211; name: security<br \/>\n\u00a0 rules:<br \/>\n# SSH \u767b\u5f55\u5931\u8d25\u8fc7\u591a&#xff08;\u9700\u8981\u90e8\u7f72 prometheus\/sshd_exporter \u5e76\u5728 sshd \u914d\u7f6e\u4e2d\u542f\u7528 SyslogFacility AUTHPRIV&#xff09;<br \/>\n\u00a0 &#8211; alert: SSHBruteForce<br \/>\n\u00a0 \u00a0 expr: rate(sshd_failed_authentication_total[5m]) &gt; 10<br \/>\n\u00a0 \u00a0\u00a0for: 2m<br \/>\n\u00a0 \u00a0 labels:<br \/>\n\u00a0 \u00a0 \u00a0 severity: warning<br \/>\n\u00a0 \u00a0 annotations:<br \/>\n\u00a0 \u00a0 \u00a0 summary:\u00a0&#034;SSH brute force detected&#034;<br \/>\n\u00a0 \u00a0 \u00a0 description:\u00a0&#034;More than 10 failed SSH auth per 5min from {{\u00a0$labels.instance }}&#034;<\/p>\n<p># \u65b0\u589e\u76d1\u542c\u7aef\u53e3&#xff08;\u88ab\u63a7\u7279\u5f81&#xff09;<br \/>\n# \u901a\u8fc7 node_exporter \u7684 textfile collector \u66b4\u9732 ss -tuln \u7edf\u8ba1\u7684\u76d1\u542c\u7aef\u53e3\u6570<br \/>\n# \u81ea\u5b9a\u4e49\u91c7\u96c6\u811a\u672c&#xff08;\u89c1 13.3 \u8282&#xff09;\u751f\u6210 node_sock_listen_count \u6307\u6807<br \/>\n\u00a0 &#8211; alert: NewListeningPort<br \/>\n\u00a0 \u00a0 expr: count by (instance) (node_sock_listen_count) &gt; on(instance) count by (instance) (node_sock_listen_count offset 1h)<br \/>\n\u00a0 \u00a0\u00a0for: 5m<br \/>\n\u00a0 \u00a0 labels:<br \/>\n\u00a0 \u00a0 \u00a0 severity: critical<br \/>\n\u00a0 \u00a0 annotations:<br \/>\n\u00a0 \u00a0 \u00a0 summary:\u00a0&#034;New listening port detected on {{\u00a0$labels.instance }}&#034;<\/p>\n<h3>14. \u5b89\u5168\u52a0\u56fa\u540e\u7684\u9a8c\u8bc1<\/h3>\n<p>\u5b8c\u6210\u52a0\u56fa\u540e&#xff0c;\u5fc5\u987b\u8fdb\u884c\u9a8c\u8bc1&#xff1a;<\/p>\n<h4>14.1 \u52a0\u56fa\u9a8c\u8bc1\u6e05\u5355<\/h4>\n<p># SSH \u914d\u7f6e\u9a8c\u8bc1<br \/>\nsshd -t<br \/>\nssh -p 22022 -o PreferredAuthentications&#061;password -o PubkeyAuthentication&#061;no admin_user&#064;127.0.0.1<br \/>\n# \u5e94\u8be5\u62a5\u9519&#xff1a;Permission denied (password refused \u6216\u76f4\u63a5\u62d2\u7edd\u8fde\u63a5)<\/p>\n<p># \u5bc6\u94a5\u767b\u5f55\u5e94\u8be5\u6210\u529f<br \/>\nssh -p 22022 -i ~\/.ssh\/id_ed25519_server.pub admin_user&#064;127.0.0.1<\/p>\n<p># root \u767b\u5f55\u5e94\u8be5\u5931\u8d25<br \/>\nssh -p 22022 root&#064;127.0.0.1<br \/>\n# \u5e94\u8be5\u62a5\u9519&#xff1a;Permission denied<\/p>\n<p># \u9632\u706b\u5899\u9a8c\u8bc1<br \/>\n# \u4ece\u5916\u90e8 IP \u8bbf\u95ee\u975e\u767d\u540d\u5355\u7aef\u53e3\u5e94\u8be5\u88ab\u62d2\u7edd<br \/>\n# \u4ece\u767d\u540d\u5355 IP \u8bbf\u95ee\u5e94\u8be5\u6b63\u5e38<\/p>\n<p># \u6587\u4ef6\u6743\u9650\u9a8c\u8bc1<br \/>\nls -la \/etc\/shadow \u00a0# \u5e94\u8be5\u663e\u793a &#8212;&#8212;&#8212;-<\/p>\n<p># SELinux \u9a8c\u8bc1&#xff08;CentOS&#xff09;<br \/>\ngetenforce \u00a0# \u5e94\u8be5\u663e\u793a Enforcing<\/p>\n<p># fail2ban \u9a8c\u8bc1<br \/>\nfail2ban-client status sshd<br \/>\n# \u5e94\u8be5\u663e\u793a\u76d1\u72f1\u72b6\u6001\u548c\u89c4\u5219<\/p>\n<p># \u670d\u52a1\u7981\u7528\u9a8c\u8bc1<br \/>\nsystemctl status telnet.socket \u00a0# \u5e94\u8be5\u663e\u793a inactive<br \/>\nsystemctl status bluetooth \u00a0# \u5e94\u8be5\u663e\u793a inactive<\/p>\n<h4>14.2 \u8bb0\u5f55\u52a0\u56fa\u62a5\u544a<\/h4>\n<p>\u6bcf\u6b21\u52a0\u56fa\u5b8c\u6210&#xff0c;\u5fc5\u987b\u8f93\u51fa\u52a0\u56fa\u62a5\u544a&#xff0c;\u5305\u542b&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u52a0\u56fa\u65f6\u95f4\u3001\u4eba\u5458<\/p>\n<\/li>\n<li>\n<p>\u4fee\u6539\u524d\u7684\u914d\u7f6e\u5907\u4efd\u8def\u5f84<\/p>\n<\/li>\n<li>\n<p>\u6bcf\u9879\u52a0\u56fa\u7684\u5177\u4f53\u64cd\u4f5c<\/p>\n<\/li>\n<li>\n<p>\u9a8c\u8bc1\u7ed3\u679c<\/p>\n<\/li>\n<li>\n<p>\u9057\u7559\u98ce\u9669\u548c\u540e\u7eed\u8ba1\u5212<\/p>\n<\/li>\n<\/ul>\n<p>cat &gt; \/opt\/security-hardening-report-$(date &#043;%Y%m%d).txt &lt;&lt;\u00a0&#039;EOF&#039;<br \/>\n\u5b89\u5168\u52a0\u56fa\u62a5\u544a<br \/>\n&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\u65e5\u671f: $(date &#043;%Y-%m-%d)<br \/>\n\u64cd\u4f5c\u4eba: admin_user<br \/>\n\u670d\u52a1\u5668: $(hostname) \/ $(curl -s ifconfig.me ||\u00a0echo&#034;N\/A&#034;)<\/p>\n<p>\u4e00\u3001\u52a0\u56fa\u9879\u76ee<br \/>\n&#8212;&#8212;&#8212;<br \/>\n1. SSH \u5b89\u5168<br \/>\n\u00a0 \u00a0&#8211; \u7aef\u53e3: 22 -&gt; 22022<br \/>\n\u00a0 \u00a0&#8211; \u7981\u7528 root \u767b\u5f55: yes<br \/>\n\u00a0 \u00a0&#8211; \u5bc6\u94a5\u767b\u5f55: yes<br \/>\n\u00a0 \u00a0&#8211; fail2ban: enabled<br \/>\n2. \u9632\u706b\u5899<br \/>\n\u00a0 \u00a0&#8211; firewalld: enabled<br \/>\n\u00a0 \u00a0&#8211; \u9ed8\u8ba4\u7b56\u7565: drop<br \/>\n\u00a0 \u00a0&#8211; \u653e\u884c\u7aef\u53e3: 22022, 80, 443<br \/>\n3. \u8d26\u6237\u5b89\u5168<br \/>\n\u00a0 \u00a0&#8211; \u5bc6\u7801\u7b56\u7565: minlen&#061;12, dcredit&#061;-1, &#8230;<br \/>\n\u00a0 \u00a0&#8211; wheel \u7ec4\u9650\u5236: enabled<br \/>\n\u00a0 \u00a0&#8211; \u7a7a\u5bc6\u7801\u8d26\u6237: 0<br \/>\n4. SELinux: Enforcing (CentOS)<br \/>\n5. \u5185\u6838\u53c2\u6570: \u5df2\u52a0\u56fa&#xff08;sysctl.conf&#xff09;<br \/>\n6. \u65e5\u5fd7\u5ba1\u8ba1: auditd enabled, rsyslog forwarded<\/p>\n<p>\u4e8c\u3001\u9a8c\u8bc1\u7ed3\u679c<br \/>\n&#8212;&#8212;&#8212;<br \/>\n&#8211; [x] SSH \u914d\u7f6e\u8bed\u6cd5\u6b63\u786e<br \/>\n&#8211; [x] root \u65e0\u6cd5\u767b\u5f55<br \/>\n&#8211; [x] fail2ban \u8fd0\u884c\u6b63\u5e38<br \/>\n&#8211; [x] firewall-cmd \u89c4\u5219\u751f\u6548<br \/>\n&#8211; [x] \u5173\u952e\u6587\u4ef6\u6743\u9650\u6b63\u786e<br \/>\n&#8211; [ ] \u4ece\u5916\u90e8 IP \u5b9e\u9645\u6d4b\u8bd5&#xff08;\u5f85\u6267\u884c&#xff09;<\/p>\n<p>\u4e09\u3001\u9057\u7559\u98ce\u9669<br \/>\n&#8212;&#8212;&#8212;<br \/>\n&#8211; [ ] \u4e91\u5e73\u53f0\u63a7\u5236\u53f0\u767b\u5f55 MFA \u672a\u914d\u7f6e<br \/>\n&#8211; [ ] \u6570\u636e\u5e93 Redis \u5bc6\u7801\u9700\u8981\u5b9a\u671f\u8f6e\u6362<\/p>\n<p>\u56db\u3001\u4e0b\u6b21\u52a0\u56fa\u8ba1\u5212<br \/>\n&#8212;&#8212;&#8212;&#8212;-<br \/>\n&#8211; \u6dfb\u52a0 AIDE \u6587\u4ef6\u5b8c\u6574\u6027\u68c0\u67e5<br \/>\n&#8211; \u914d\u7f6e OSSEC \u4e3b\u673a\u5165\u4fb5\u68c0\u6d4b<br \/>\nEOF<\/p>\n<h3>15. \u603b\u7ed3<\/h3>\n<p>\u5b89\u5168\u52a0\u56fa\u4e0d\u662f\u4e00\u6b21\u6027\u5de5\u4f5c&#xff0c;\u800c\u662f\u6301\u7eed\u7684\u8fc7\u7a0b\u3002\u6838\u5fc3\u539f\u5219\u8981\u8bb0\u4f4f&#xff1a;<\/p>\n<p>\u6700\u5c0f\u6743\u9650\u539f\u5219&#xff1a;\u00a0\u4e0d\u9700\u8981\u7684\u7aef\u53e3\u5c31\u4e0d\u5f00&#xff0c;\u4e0d\u9700\u8981\u7684\u670d\u52a1\u5c31\u7981\u7528&#xff0c;\u4e0d\u9700\u8981\u7684\u529f\u80fd\u5c31\u5173\u95ed\u3002\u6bcf\u4e2a\u5f00\u653e\u90fd\u5e94\u8be5\u662f\u660e\u786e\u6709\u7406\u7531\u7684\u3002<\/p>\n<p>\u7eb5\u6df1\u9632\u5fa1\u539f\u5219&#xff1a;\u00a0\u6bcf\u4e00\u5c42\u9632\u7ebf\u5931\u6548\u540e\u8fd8\u6709\u4e0b\u4e00\u5c42\u3002SSH \u5bc6\u94a5\u767b\u5f55\u5931\u6548\u8fd8\u6709 fail2ban \u5c01\u7981&#xff0c;\u9632\u706b\u5899\u5931\u6548\u8fd8\u6709 SELinux \u9650\u5236&#xff0c;\u540e\u95e8\u690d\u5165\u8fd8\u6709 auditd \u8bb0\u5f55\u3002<\/p>\n<p>\u53ef\u5ba1\u8ba1\u539f\u5219&#xff1a;\u00a0\u4e00\u5207\u64cd\u4f5c\u7686\u6709\u8bb0\u5f55&#xff0c;\u6240\u6709\u53d8\u66f4\u53ef\u8ffd\u6eaf\u3002\u65e5\u5fd7\u4e0d\u4ec5\u8981\u5728&#xff0c;\u800c\u4e14\u4e0d\u80fd\u88ab\u7be1\u6539\u3002\u5b9a\u671f\u68c0\u67e5\u5ba1\u8ba1\u65e5\u5fd7\u6bd4\u88ab\u653b\u51fb\u540e\u624d\u53d1\u73b0\u8981\u597d\u5f97\u591a\u3002<\/p>\n<p>\u52a0\u56fa\u540e\u8981\u9a8c\u8bc1&#xff1a;\u00a0\u914d\u7f6e\u6539\u4e86\u4e0d\u4ee3\u8868\u751f\u6548&#xff0c;\u8981\u5b9e\u9645\u6d4b\u8bd5\u3002\u6bcf\u505a\u4e00\u9879\u52a0\u56fa&#xff0c;\u9a6c\u4e0a\u9a8c\u8bc1\u662f\u5426\u751f\u6548\u3001\u662f\u5426\u5f71\u54cd\u6b63\u5e38\u529f\u80fd\u3002<\/p>\n<p>\u4fdd\u6301\u66f4\u65b0&#xff1a;\u00a0\u6f0f\u6d1e\u6bcf\u5929\u90fd\u5728\u88ab\u53d1\u73b0&#xff0c;\u7cfb\u7edf\u6bcf\u5929\u90fd\u5728\u8fd0\u884c\u65b0\u7684\u653b\u51fb\u3002\u5b89\u5168\u52a0\u56fa\u662f\u6301\u7eed\u5de5\u4f5c&#xff0c;\u4e0d\u662f\u505a\u5b8c\u4e00\u6b21\u5c31\u80fd\u9ad8\u6795\u65e0\u5fe7\u3002<\/p>\n<p>\u6700\u540e\u63d0\u9192&#xff1a;\u52a0\u56fa\u662f\u4e3a\u4e86\u63d0\u9ad8\u653b\u51fb\u6210\u672c&#xff0c;\u800c\u4e0d\u662f\u8ba9\u670d\u52a1\u5668\u5b8c\u5168\u4e0d\u88ab\u653b\u7834\u3002\u518d\u5b8c\u5584\u7684\u52a0\u56fa\u4e5f\u65e0\u6cd5\u4fdd\u8bc1 100% \u5b89\u5168&#xff0c;\u6240\u4ee5\u65e5\u5fd7\u76d1\u63a7\u3001\u5165\u4fb5\u68c0\u6d4b\u3001\u5e94\u6025\u54cd\u5e94\u80fd\u529b\u540c\u6837\u91cd\u8981\u3002\u9632\u5b88\u662f\u4f53\u7cfb&#xff0c;\u52a0\u56fa\u53ea\u662f\u7b2c\u4e00\u6b65\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u670d\u52a1\u5668\u88ab\u653b\u51fb&#xff01;\u5b8c\u6574\u5b89\u5168\u52a0\u56fa\u6e05\u5355\u6c47\u603b<br \/>\n\u670d\u52a1\u5668\u88ab\u9ed1\u4e0d\u662f\u5c0f\u6982\u7387\u4e8b\u4ef6\u3002\u53ea\u8981\u670d\u52a1\u5668\u66b4\u9732\u5728\u516c\u7f51&#xff0c;\u6bcf\u65f6\u6bcf\u523b\u90fd\u5728\u88ab\u626b\u63cf\u3001\u88ab\u5c1d\u8bd5\u5f31\u53e3\u4ee4\u3001\u88ab\u63a2\u6d4b\u6f0f\u6d1e\u3002\u5b89\u5168\u52a0\u56fa\u4e0d\u662f\\&#8221;\u7528\u4e0d\u7528\u5fc3\\&#8221;\u7684\u95ee\u9898&#xff0c;\u800c\u662f\\&#8221;\u6709\u6ca1\u6709\u505a\\&#8221;\u7684\u95ee\u9898\u3002\u8fd9\u7bc7\u6587\u7ae0\u7ed9\u51fa\u4e00\u4efd\u5b8c\u6574\u7684 Linux \u670d\u52a1\u5668\u5b89\u5168\u52a0\u56fa\u6e05\u5355&#xff0c;\u6db5\u76d6\u8d26\u6237\u5b89\u5168\u3001SSH \u52a0\u56fa\u3001\u9632\u706b\u5899\u914d\u7f6e\u3001\u670d\u52a1\u5b89\u5168\u3001\u65e5\u5fd7\u5ba1\u8ba1\u3001\u5165\u4fb5\u68c0\u6d4b\u7b49\u6838\u5fc3\u73af\u8282\u3002\u6bcf\u4e2a\u6761\u76ee\u90fd\u8bb2\u89e3\u4e3a\u4ec0\u4e48\u8981\u505a\u3001\u600e\u4e48\u505a\u3001\u4e0d\u505a\u7684\u98ce\u9669\u662f\u4ec0\u4e48&#xff0c;\u8ba9\u521d\u4e2d\u7ea7\u8fd0\u7ef4\u5de5\u7a0b\u5e08\u80fd\u7167\u7740\u64cd\u4f5c\u3001\u843d\u5730<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[61,43,44],"topic":[],"class_list":["post-95958","post","type-post","status-publish","format-standard","hentry","category-server","tag-61","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u670d\u52a1\u5668\u88ab\u653b\u51fb\uff01\u5b8c\u6574\u5b89\u5168\u52a0\u56fa\u6e05\u5355\u6c47\u603b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/95958.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u670d\u52a1\u5668\u88ab\u653b\u51fb\uff01\u5b8c\u6574\u5b89\u5168\u52a0\u56fa\u6e05\u5355\u6c47\u603b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u670d\u52a1\u5668\u88ab\u653b\u51fb&#xff01;\u5b8c\u6574\u5b89\u5168\u52a0\u56fa\u6e05\u5355\u6c47\u603b \u670d\u52a1\u5668\u88ab\u9ed1\u4e0d\u662f\u5c0f\u6982\u7387\u4e8b\u4ef6\u3002\u53ea\u8981\u670d\u52a1\u5668\u66b4\u9732\u5728\u516c\u7f51&#xff0c;\u6bcf\u65f6\u6bcf\u523b\u90fd\u5728\u88ab\u626b\u63cf\u3001\u88ab\u5c1d\u8bd5\u5f31\u53e3\u4ee4\u3001\u88ab\u63a2\u6d4b\u6f0f\u6d1e\u3002\u5b89\u5168\u52a0\u56fa\u4e0d\u662f&quot;\u7528\u4e0d\u7528\u5fc3&quot;\u7684\u95ee\u9898&#xff0c;\u800c\u662f&quot;\u6709\u6ca1\u6709\u505a&quot;\u7684\u95ee\u9898\u3002\u8fd9\u7bc7\u6587\u7ae0\u7ed9\u51fa\u4e00\u4efd\u5b8c\u6574\u7684 Linux \u670d\u52a1\u5668\u5b89\u5168\u52a0\u56fa\u6e05\u5355&#xff0c;\u6db5\u76d6\u8d26\u6237\u5b89\u5168\u3001SSH \u52a0\u56fa\u3001\u9632\u706b\u5899\u914d\u7f6e\u3001\u670d\u52a1\u5b89\u5168\u3001\u65e5\u5fd7\u5ba1\u8ba1\u3001\u5165\u4fb5\u68c0\u6d4b\u7b49\u6838\u5fc3\u73af\u8282\u3002\u6bcf\u4e2a\u6761\u76ee\u90fd\u8bb2\u89e3\u4e3a\u4ec0\u4e48\u8981\u505a\u3001\u600e\u4e48\u505a\u3001\u4e0d\u505a\u7684\u98ce\u9669\u662f\u4ec0\u4e48&#xff0c;\u8ba9\u521d\u4e2d\u7ea7\u8fd0\u7ef4\u5de5\u7a0b\u5e08\u80fd\u7167\u7740\u64cd\u4f5c\u3001\u843d\u5730\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/95958.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-26T23:25:01+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"18 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/95958.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/95958.html\",\"name\":\"\u670d\u52a1\u5668\u88ab\u653b\u51fb\uff01\u5b8c\u6574\u5b89\u5168\u52a0\u56fa\u6e05\u5355\u6c47\u603b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-26T23:25:01+00:00\",\"dateModified\":\"2026-08-26T23:25:01+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/95958.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/95958.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/95958.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u670d\u52a1\u5668\u88ab\u653b\u51fb\uff01\u5b8c\u6574\u5b89\u5168\u52a0\u56fa\u6e05\u5355\u6c47\u603b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u670d\u52a1\u5668\u88ab\u653b\u51fb\uff01\u5b8c\u6574\u5b89\u5168\u52a0\u56fa\u6e05\u5355\u6c47\u603b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/95958.html","og_locale":"zh_CN","og_type":"article","og_title":"\u670d\u52a1\u5668\u88ab\u653b\u51fb\uff01\u5b8c\u6574\u5b89\u5168\u52a0\u56fa\u6e05\u5355\u6c47\u603b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u670d\u52a1\u5668\u88ab\u653b\u51fb&#xff01;\u5b8c\u6574\u5b89\u5168\u52a0\u56fa\u6e05\u5355\u6c47\u603b \u670d\u52a1\u5668\u88ab\u9ed1\u4e0d\u662f\u5c0f\u6982\u7387\u4e8b\u4ef6\u3002\u53ea\u8981\u670d\u52a1\u5668\u66b4\u9732\u5728\u516c\u7f51&#xff0c;\u6bcf\u65f6\u6bcf\u523b\u90fd\u5728\u88ab\u626b\u63cf\u3001\u88ab\u5c1d\u8bd5\u5f31\u53e3\u4ee4\u3001\u88ab\u63a2\u6d4b\u6f0f\u6d1e\u3002\u5b89\u5168\u52a0\u56fa\u4e0d\u662f\"\u7528\u4e0d\u7528\u5fc3\"\u7684\u95ee\u9898&#xff0c;\u800c\u662f\"\u6709\u6ca1\u6709\u505a\"\u7684\u95ee\u9898\u3002\u8fd9\u7bc7\u6587\u7ae0\u7ed9\u51fa\u4e00\u4efd\u5b8c\u6574\u7684 Linux \u670d\u52a1\u5668\u5b89\u5168\u52a0\u56fa\u6e05\u5355&#xff0c;\u6db5\u76d6\u8d26\u6237\u5b89\u5168\u3001SSH \u52a0\u56fa\u3001\u9632\u706b\u5899\u914d\u7f6e\u3001\u670d\u52a1\u5b89\u5168\u3001\u65e5\u5fd7\u5ba1\u8ba1\u3001\u5165\u4fb5\u68c0\u6d4b\u7b49\u6838\u5fc3\u73af\u8282\u3002\u6bcf\u4e2a\u6761\u76ee\u90fd\u8bb2\u89e3\u4e3a\u4ec0\u4e48\u8981\u505a\u3001\u600e\u4e48\u505a\u3001\u4e0d\u505a\u7684\u98ce\u9669\u662f\u4ec0\u4e48&#xff0c;\u8ba9\u521d\u4e2d\u7ea7\u8fd0\u7ef4\u5de5\u7a0b\u5e08\u80fd\u7167\u7740\u64cd\u4f5c\u3001\u843d\u5730","og_url":"https:\/\/www.wsisp.com\/helps\/95958.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-26T23:25:01+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"18 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/95958.html","url":"https:\/\/www.wsisp.com\/helps\/95958.html","name":"\u670d\u52a1\u5668\u88ab\u653b\u51fb\uff01\u5b8c\u6574\u5b89\u5168\u52a0\u56fa\u6e05\u5355\u6c47\u603b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-26T23:25:01+00:00","dateModified":"2026-08-26T23:25:01+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/95958.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/95958.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/95958.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u670d\u52a1\u5668\u88ab\u653b\u51fb\uff01\u5b8c\u6574\u5b89\u5168\u52a0\u56fa\u6e05\u5355\u6c47\u603b"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/95958","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=95958"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/95958\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=95958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=95958"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=95958"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=95958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}