{"id":442455,"date":"2026-02-27T16:49:16","date_gmt":"2026-02-27T08:49:16","guid":{"rendered":"https:\/\/idc.net\/help\/?p=442455"},"modified":"2026-02-12T16:51:56","modified_gmt":"2026-02-12T08:51:56","slug":"ubuntu-server-ssh-%e5%ae%89%e5%85%a8%e9%85%8d%e7%bd%ae%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/442455\/","title":{"rendered":"Ubuntu Server SSH \u5b89\u5168\u914d\u7f6e\u6307\u5357"},"content":{"rendered":"<p dir=\"auto\">SSH \u662f Ubuntu Server \u6700\u5e38\u89c1\u7684\u8fdc\u7a0b\u7ba1\u7406\u5165\u53e3\uff0c\u540c\u65f6\u4e5f\u662f\u653b\u51fb\u8005\u6700\u4f18\u5148\u626b\u63cf\u7684\u76ee\u6807\u3002\u5728 2026 \u5e74\uff0c\u4e92\u8054\u7f51\u4e0a\u7684\u81ea\u52a8\u5316\u626b\u63cf\u548c\u66b4\u529b\u7834\u89e3\u5de5\u5177\u5df2\u9ad8\u5ea6\u6210\u719f\uff0c\u5355\u7eaf\u4f9d\u8d56\u5bc6\u7801\u6216\u9ed8\u8ba4\u914d\u7f6e\u5df2\u4e0d\u8db3\u4ee5\u62b5\u5fa1\u5a01\u80c1\u3002Canonical \u5b98\u65b9\u6587\u6863\u3001CIS \u57fa\u51c6\u4ee5\u53ca\u793e\u533a\u5b9e\u8df5\u5747\u5f3a\u8c03\uff1a<strong>SSH \u5b89\u5168\u7684\u6838\u5fc3\u662f\u201c\u5bc6\u94a5\u8ba4\u8bc1 + \u6700\u5c0f\u66b4\u9732 + \u52a8\u6001\u9632\u5fa1\u201d<\/strong>\u3002<\/p>\n<p dir=\"auto\">\u672c\u6307\u5357\u9002\u7528\u4e8e Ubuntu 24.04 LTS\uff08Noble Numbat\uff09\u53ca\u540e\u7eed\u7248\u672c\uff0c\u805a\u7126\u751f\u4ea7\u73af\u5883\u6700\u52a1\u5b9e\u3001\u53ef\u843d\u5730\u7684\u9ad8\u6536\u76ca\u52a0\u56fa\u8def\u5f84\u3002\u4f18\u5148\u7ea7\u4ece\u9ad8\u5230\u4f4e\u6392\u5217\u3002<\/p>\n<h2 dir=\"auto\">1. \u6838\u5fc3\u5b89\u5168\u6a21\u578b\u4e0e\u5206\u5c42\u9632\u5fa1<\/h2>\n<p dir=\"auto\">\u73b0\u4ee3 SSH \u5b89\u5168\u91c7\u7528\u7eb5\u6df1\u9632\u5fa1\u67b6\u6784\uff1a<\/p>\n<ul dir=\"auto\">\n<li><strong>\u8ba4\u8bc1\u5c42<\/strong>\uff1a\u5f3a\u5236\u516c\u94a5\uff08ed25519 \u4f18\u5148\uff09\uff0c\u7981\u7528\u5bc6\u7801<\/li>\n<li><strong>\u8bbf\u95ee\u63a7\u5236\u5c42<\/strong>\uff1a\u7981\u6b62 root \u767b\u5f55\u3001\u9650\u5236\u7528\u6237\/\u7ec4\/IP<\/li>\n<li><strong>\u534f\u8bae\u4e0e\u52a0\u5bc6\u5c42<\/strong>\uff1a\u7981\u7528\u5f31\u7b97\u6cd5\u3001\u4f18\u5148\u73b0\u4ee3\u5bc6\u7801\u5957\u4ef6<\/li>\n<li><strong>\u8fde\u63a5\u7ba1\u7406\u5c42<\/strong>\uff1a\u9650\u5236\u5c1d\u8bd5\u6b21\u6570\u3001\u8d85\u65f6\u3001\u901f\u7387\u9650\u5236<\/li>\n<li><strong>\u5165\u4fb5\u68c0\u6d4b\u5c42<\/strong>\uff1aFail2Ban \u6216 CrowdSec \u52a8\u6001\u5c01\u7981<\/li>\n<li><strong>\u7f51\u7edc\u5c42<\/strong>\uff1aUFW\/nftables \u9650\u5236\u6765\u6e90 + \u7aef\u53e3\u53d8\u66f4\uff08\u53ef\u9009\uff09<\/li>\n<li><strong>\u9ad8\u7ea7\u5c42<\/strong>\uff1aMFA\uff082FA\uff09\u3001bastion \u4e3b\u673a\u3001VPN \u524d\u7f6e\u3001USG \u81ea\u52a8\u5316 CIS \u5408\u89c4<\/li>\n<\/ul>\n<h2 dir=\"auto\">2. \u57fa\u7840\u914d\u7f6e\uff08\u5fc5\u987b\u7acb\u5373\u6267\u884c\uff09<\/h2>\n<h3 dir=\"auto\">2.1 \u521b\u5efa\u4e13\u7528\u7ba1\u7406\u7528\u6237\uff08\u7981\u7528 root \u8fdc\u7a0b\u767b\u5f55\uff09<\/h3>\n<p dir=\"auto\">\u76f4\u63a5 root \u767b\u5f55\u662f\u6700\u5927\u98ce\u9669\u70b9\u3002\u521b\u5efa\u666e\u901a\u7528\u6237 + sudo \u6743\u9650\uff1a<\/p>\n<ul dir=\"auto\">\n<li>\u65b0\u7528\u6237\uff1aadduser youradmin<\/li>\n<li>\u52a0\u5165 sudo\uff1ausermod -aG sudo youradmin<\/li>\n<li>\u6d4b\u8bd5\u65b0\u7528\u6237 SSH \u767b\u5f55\u6210\u529f\u540e\uff0c\u9501\u5b9a root \u5bc6\u7801\uff08\u53ef\u9009\uff09\uff1apasswd -l root<\/li>\n<\/ul>\n<h3 dir=\"auto\">2.2 \u914d\u7f6e SSH \u5bc6\u94a5\u8ba4\u8bc1\uff08\u7981\u7528\u5bc6\u7801\u767b\u5f55\uff09<\/h3>\n<p dir=\"auto\"><strong>\u5bc6\u94a5\u8ba4\u8bc1\u662f 2026 \u5e74 SSH \u5b89\u5168\u57fa\u77f3<\/strong>\u3002ed25519 \u66f2\u7ebf\u5df2\u6210\u4e3a\u4e8b\u5b9e\u6807\u51c6\uff08\u5b89\u5168\u6027\u9ad8\u3001\u8ba1\u7b97\u6548\u7387\u4f18\u4e8e rsa-2048\u3001ecdsa\uff09\u3002<\/p>\n<ol dir=\"auto\">\n<li>\n<p dir=\"auto\">\u672c\u5730\u751f\u6210\u5bc6\u94a5\uff08\u63a8\u8350 ed25519\uff09\uff1a<\/p>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>text<\/div>\n<div><\/div>\n<div>\n<pre tabindex=\"0\"><code>ssh-keygen -t ed25519 -C \"your_email@example.com - 2026\"<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<p dir=\"auto\">\u4e0a\u4f20\u516c\u94a5\u5230\u670d\u52a1\u5668\uff08\u6700\u5b89\u5168\u65b9\u5f0f\uff09\uff1a<\/p>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>text<\/div>\n<div><\/div>\n<div>\n<pre tabindex=\"0\"><code>ssh-copy-id youradmin@\u670d\u52a1\u5668IP<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<p dir=\"auto\">\u7f16\u8f91\u670d\u52a1\u5668\u7aef\u914d\u7f6e\uff08\u63a8\u8350\u4f7f\u7528 drop-in \u65b9\u5f0f\uff0c\u907f\u514d\u8986\u76d6\u5347\u7ea7\uff09\uff1a \u521b\u5efa \/etc\/ssh\/sshd_config.d\/hardening.conf\uff08\u4f18\u5148\u7ea7\u9ad8\u4e8e\u4e3b\u6587\u4ef6\uff09\uff1a<\/p>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>text<\/div>\n<div><\/div>\n<div>\n<pre tabindex=\"0\"><code># \u8ba4\u8bc1\u65b9\u5f0f\r\nPubkeyAuthentication yes\r\nPasswordAuthentication no\r\nKbdInteractiveAuthentication no\r\nPermitEmptyPasswords no\r\n\r\n# \u7981\u6b62 root \u767b\u5f55\r\nPermitRootLogin no\r\n\r\n# \u9650\u5236\u5c1d\u8bd5\u4e0e\u8d85\u65f6\r\nMaxAuthTries 3\r\nLoginGraceTime 20\r\nMaxStartups 10:30:60\r\n\r\n# \u8fde\u63a5\u4fdd\u6d3b\uff08\u9632 NAT \u8d85\u65f6\u65ad\u5f00\uff09\r\nClientAliveInterval 300\r\nClientAliveCountMax 3\r\n\r\n# \u53ea\u5141\u8bb8\u7279\u5b9a\u7528\u6237\uff08\u53ef\u9009\uff09\r\n# AllowUsers youradmin deploy\r\n\r\n# \u73b0\u4ee3\u52a0\u5bc6\u4f18\u5148\uff08\u7981\u7528\u5f31\u7b97\u6cd5\uff09\r\nCiphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com\r\nMACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com\r\nKexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<p dir=\"auto\">\u6d4b\u8bd5\u914d\u7f6e\u8bed\u6cd5\uff1a<\/p>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>text<\/div>\n<div><\/div>\n<div>\n<pre tabindex=\"0\"><code>sudo sshd -t<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<p dir=\"auto\">\u91cd\u542f\u670d\u52a1\uff1a<\/p>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>text<\/div>\n<div><\/div>\n<div>\n<pre tabindex=\"0\"><code>sudo systemctl restart ssh<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/li>\n<\/ol>\n<p dir=\"auto\"><strong>\u5173\u952e<\/strong>\uff1a\u5148\u5728\u65b0\u7ec8\u7aef\u9a8c\u8bc1\u5bc6\u94a5\u767b\u5f55\u6210\u529f\uff0c\u518d\u5173\u95ed\u5f53\u524d\u4f1a\u8bdd\u3002\u5426\u5219\u5bb9\u6613\u9501\u6b7b\u81ea\u5df1\u3002<\/p>\n<h2 dir=\"auto\">3. \u7f51\u7edc\u4e0e\u9632\u706b\u5899\u9650\u5236<\/h2>\n<ul dir=\"auto\">\n<li><strong>UFW \u6700\u5c0f\u89c4\u5219<\/strong>\uff08\u63a8\u8350\uff09\uff1a\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>text<\/div>\n<div><\/div>\n<div>\n<pre tabindex=\"0\"><code>sudo ufw default deny incoming\r\nsudo ufw default allow outgoing\r\nsudo ufw allow OpenSSH   # \u6216 allow \u4f60\u7684\u7aef\u53e3\/tcp\r\nsudo ufw enable<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/li>\n<li><strong>\u9650\u5236\u6765\u6e90 IP<\/strong>\uff08\u6700\u9ad8\u5b89\u5168\u63d0\u5347\uff09\uff1a\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>text<\/div>\n<div><\/div>\n<div>\n<pre tabindex=\"0\"><code>sudo ufw allow from \u4f60\u7684\u5bb6IP\/32 to any port 22\r\nsudo ufw allow from \u4f60\u7684\u516c\u53f8\u5b50\u7f51\/24 to any port 22<\/code><\/pre>\n<\/div>\n<\/div>\n<div><\/div>\n<\/div>\n<\/div>\n<\/li>\n<li><strong>\u53ef\u9009\u6539\u7aef\u53e3<\/strong>\uff08\u964d\u4f4e\u626b\u63cf\u566a\u97f3\uff0c\u975e\u672c\u8d28\u5b89\u5168\uff09\uff1a \u5728 hardening.conf \u4e2d\u52a0 Port 5822\uff0c\u7136\u540e UFW \u5bf9\u5e94\u653e\u884c\u3002<\/li>\n<\/ul>\n<h2 dir=\"auto\">4. \u5165\u4fb5\u68c0\u6d4b\u4e0e\u52a8\u6001\u9632\u5fa1\uff08\u5f3a\u70c8\u63a8\u8350\uff09<\/h2>\n<h3 dir=\"auto\">4.1 Fail2Ban\uff08\u7ecf\u5178\u3001\u8f7b\u91cf\uff09<\/h3>\n<p dir=\"auto\">\u76d1\u63a7 auth.log\uff0c\u5931\u8d25\u5c1d\u8bd5\u8fc7\u591a\u81ea\u52a8\u5c01\u7981 IP\u3002<\/p>\n<p dir=\"auto\">\u5b89\u88c5\uff1a<\/p>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>text<\/div>\n<div>\n<pre tabindex=\"0\"><code>sudo apt install fail2ban<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p dir=\"auto\">\u9ed8\u8ba4\u5df2\u8986\u76d6 sshd jail\u3002\u81ea\u5b9a\u4e49 \/etc\/fail2ban\/jail.local\uff1a<\/p>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>text<\/div>\n<div>\n<pre tabindex=\"0\"><code>[sshd]\r\nenabled = true\r\nport = 22          # \u6216\u4f60\u7684\u7aef\u53e3\r\nmaxretry = 3\r\nbantime = 24h\r\nfindtime = 10m<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h3 dir=\"auto\">4.2 CrowdSec<\/h3>\n<p dir=\"auto\">\u793e\u533a\u5a01\u80c1\u60c5\u62a5\u5171\u4eab + bouncer \u5230 nftables\u3002<\/p>\n<p dir=\"auto\">\u5b89\u88c5\uff1a<\/p>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>text<\/div>\n<div>\n<div><\/div>\n<\/div>\n<div>\n<pre tabindex=\"0\"><code>curl -s https:\/\/packagecloud.io\/install\/repositories\/crowdsec\/crowdsec\/script.deb.sh | sudo bash\r\nsudo apt install crowdsec crowdsec-firewall-bouncer-nftables<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p dir=\"auto\">\u914d\u7f6e SSH \u91c7\u96c6\uff1a \u521b\u5efa \/etc\/crowdsec\/acquis.d\/sshd.yaml\uff1a<\/p>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>text<\/div>\n<div>\n<div>\n<div><\/div>\n<\/div>\n<\/div>\n<div>\n<pre tabindex=\"0\"><code>filenames:\r\n  - \/var\/log\/auth.log\r\nlabels:\r\n  type: syslog<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p dir=\"auto\">\u542f\u52a8\u5e76\u76d1\u63a7\uff1a<\/p>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>text<\/div>\n<div>\n<pre tabindex=\"0\"><code>sudo systemctl enable --now crowdsec\r\ncscli metrics<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p dir=\"auto\">CrowdSec \u4f18\u52bf\uff1a\u5171\u4eab\u9ed1\u540d\u5355\u3001\u573a\u666f\u68c0\u6d4b\uff08\u4e0d\u4ec5\u4ec5\u662f brute-force\uff09\u3001\u652f\u6301\u591a\u670d\u52a1\u3002<\/p>\n<h2 dir=\"auto\">5. \u9ad8\u7ea7\u9009\u9879\uff08\u89c6\u9700\u6c42\u542f\u7528\uff09<\/h2>\n<ul dir=\"auto\">\n<li><strong>MFA \/ 2FA<\/strong>\uff1aGoogle Authenticator PAM \u6a21\u5757\uff08\u9002\u7528\u4e8e\u9ad8\u5b89\u5168\u9700\u6c42\uff09<\/li>\n<li><strong>\u8bc1\u4e66\u8ba4\u8bc1<\/strong>\uff1aSSH CA \u7b7e\u540d\u5bc6\u94a5\uff08\u5927\u89c4\u6a21\u7ba1\u7406\uff09<\/li>\n<li><strong>Bastion \/ Jump Host<\/strong>\uff1a\u6240\u6709\u7ba1\u7406\u901a\u8fc7\u8df3\u677f\u673a<\/li>\n<li><strong>VPN \u524d\u7f6e<\/strong>\uff1aWireGuard \/ Tailscale \/ ZeroTier\uff0c\u53ea\u5728\u5185\u7f51\u66b4\u9732 SSH<\/li>\n<li><strong>USG + CIS \u81ea\u52a8\u5316<\/strong>\uff1aUbuntu Pro \u7528\u6237\u542f\u7528 USG\uff0c\u5e94\u7528 cis_level1_server profile\uff08\u5305\u542b SSH \u76f8\u5173\u89c4\u5219\uff09<\/li>\n<\/ul>\n<h2 dir=\"auto\">6. \u9a8c\u8bc1\u4e0e\u5ba1\u8ba1\u6e05\u5355<\/h2>\n<ul dir=\"auto\">\n<li>sshd -T | grep -iE 'password|permitroot|pubkey|auth' \u2192 \u68c0\u67e5\u5173\u952e\u8bbe\u7f6e<\/li>\n<li>journalctl -u ssh -n 100 \u2192 \u89c2\u5bdf\u767b\u5f55\u5c1d\u8bd5<\/li>\n<li>fail2ban-client status sshd \u6216 cscli decisions list \u2192 \u67e5\u770b\u5c01\u7981<\/li>\n<li>ssh-audit localhost\uff08\u5b89\u88c5 ssh-audit \u5de5\u5177\uff09\u2192 \u81ea\u52a8\u5316\u626b\u63cf\u5f31\u70b9<\/li>\n<li>USG audit\uff1asudo usg audit cis_level1_server\uff08Pro \u7528\u6237\uff09<\/li>\n<\/ul>\n<h2 dir=\"auto\">\u7ed3\u8bed<\/h2>\n<p dir=\"auto\">2026 \u5e74\u6700\u5b89\u5168\u7684 SSH \u914d\u7f6e\u516c\u5f0f\uff1a<strong>\u5bc6\u94a5\u8ba4\u8bc1\uff08ed25519\uff09 + \u7981\u7528\u5bc6\u7801 + \u7981\u6b62 root + \u9650\u5236\u5c1d\u8bd5 + UFW \u6765\u6e90\u9650\u5236 + CrowdSec\/Fail2Ban \u52a8\u6001\u5c01\u7981<\/strong>\u3002<\/p>\n<p dir=\"auto\">\u505a\u5230\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u66b4\u529b\u7834\u89e3\u6210\u529f\u7387\u63a5\u8fd1\u96f6\uff0c\u65e5\u5e38\u7ba1\u7406\u4ecd\u4fdd\u6301\u9ad8\u6548\u3002\u751f\u4ea7\u73af\u5883\u5efa\u8bae\u7ed3\u5408 Ubuntu Pro \u7684 USG \u5de5\u5177\u5b9e\u73b0\u81ea\u52a8\u5316\u5408\u89c4\u5ba1\u8ba1\uff0c\u907f\u514d\u624b\u52a8\u9057\u6f0f\u3002<\/p>\n<p dir=\"auto\">\u5982\u679c\u4f60\u7684\u670d\u52a1\u5668\u66b4\u9732\u5728\u516c\u7f51\uff0c<strong>\u4f18\u5148\u5b9e\u65bd\u5bc6\u94a5 + CrowdSec + IP \u767d\u540d\u5355<\/strong>\uff0c\u8fd9\u4e09\u5c42\u7ec4\u5408\u5728\u5f53\u524d\u5a01\u80c1\u73af\u5883\u4e0b\u6027\u4ef7\u6bd4\u6700\u9ad8\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SSH \u662f Ubuntu Server \u6700\u5e38\u89c1\u7684\u8fdc\u7a0b\u7ba1\u7406\u5165\u53e3\uff0c\u540c\u65f6\u4e5f\u662f\u653b\u51fb\u8005\u6700\u4f18\u5148\u626b\u63cf\u7684\u76ee\u6807\u3002\u5728 2026 \u5e74 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[],"class_list":["post-442455","post","type-post","status-publish","format-standard","hentry","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/442455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=442455"}],"version-history":[{"count":1,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/442455\/revisions"}],"predecessor-version":[{"id":442456,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/442455\/revisions\/442456"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=442455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=442455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=442455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}