{"id":161077,"date":"2019-10-26T09:00:05","date_gmt":"2019-10-26T01:00:05","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=161077"},"modified":"2019-10-14T14:54:59","modified_gmt":"2019-10-14T06:54:59","slug":"strong-linux-server","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/strong-linux-server.html","title":{"rendered":"\u5f3a\u5316Linux \u670d\u52a1\u5668\u76847\u4e2a\u6b65\u9aa4"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u8fd9\u7bc7\u5165\u95e8\u6587\u7ae0\u5c06\u5411\u4f60\u4ecb\u7ecd\u57fa\u672c\u7684 Linux \u670d\u52a1\u5668\u5b89\u5168\u77e5\u8bc6\u3002\u867d\u7136\u4e3b\u8981\u9488\u5bf9 Debian\/Ubuntu\uff0c\u4f46\u662f\u4f60\u53ef\u4ee5\u5c06\u6b64\u5904\u4ecb\u7ecd\u7684\u6240\u6709\u5185\u5bb9\u5e94\u7528\u4e8e\u5176\u4ed6 Linux \u53d1\u884c\u7248\u3002\u6211\u4e5f\u9f13\u52b1\u4f60\u7814\u7a76\u8fd9\u4efd\u6750\u6599\uff0c\u5e76\u5728\u9002\u7528\u7684\u60c5\u51b5\u4e0b\u8fdb\u884c\u6269\u5c55\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
1\u3001\u66f4\u65b0\u4f60\u7684\u670d\u52a1\u5668<\/strong><\/div>\n

\u4fdd\u62a4\u670d\u52a1\u5668\u5b89\u5168\u7684\u7b2c\u4e00\u4ef6\u4e8b\u662f\u66f4\u65b0\u672c\u5730\u5b58\u50a8\u5e93\uff0c\u5e76\u901a\u8fc7\u5e94\u7528\u6700\u65b0\u7684\u4fee\u8865\u7a0b\u5e8f\u6765\u5347\u7ea7\u64cd\u4f5c\u7cfb\u7edf\u548c\u5df2\u5b89\u88c5\u7684\u5e94\u7528\u7a0b\u5e8f\u3002
\n\u5728 Ubuntu \u548c Debian \u4e0a\uff1a<\/p>\n

$ sudo apt update && sudo apt upgrade -y<\/pre>\n

\u5728 Fedora\u3001CentOS \u6216 RHEL\uff1a<\/p>\n

$ sudo dnf upgrade<\/pre>\n
2\u3001\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7279\u6743\u7528\u6237<\/strong><\/div>\n

\u63a5\u4e0b\u6765\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7528\u6237\u5e10\u6237\u3002\u6c38\u8fdc\u4e0d\u8981\u4ee5 root \u8eab\u4efd\u767b\u5f55\u670d\u52a1\u5668\uff0c\u800c\u662f\u521b\u5efa\u4f60\u81ea\u5df1\u7684\u5e10\u6237\uff08\u7528\u6237\uff09\uff0c\u8d4b\u4e88\u5b83 sudo \u6743\u9650\uff0c\u7136\u540e\u4f7f\u7528\u5b83\u767b\u5f55\u4f60\u7684\u670d\u52a1\u5668\u3002
\n\u9996\u5148\u521b\u5efa\u4e00\u4e2a\u65b0\u7528\u6237\uff1a<\/p>\n

$ adduser <\/username><\/pre>\n

\u901a\u8fc7\u5c06 sudo \u7ec4\uff08-G\uff09\u9644\u52a0\uff08-a\uff09\u5230\u7528\u6237\u7684\u7ec4\u6210\u5458\u8eab\u4efd\u91cc\uff0c\u4ece\u800c\u6388\u4e88\u65b0\u7528\u6237\u5e10\u6237 sudo \u6743\u9650\uff1a<\/p>\n

$ usermod -a -G sudo <\/username><\/pre>\n
3\u3001\u4e0a\u4f20\u4f60\u7684 SSH \u5bc6\u94a5<\/strong><\/div>\n

\u4f60\u5e94\u8be5\u4f7f\u7528 SSH \u5bc6\u94a5\u767b\u5f55\u5230\u65b0\u670d\u52a1\u5668\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 ssh-copy-id \u547d\u4ee4\u5c06\u9884\u751f\u6210\u7684 SSH \u5bc6\u94a5\u4e0a\u4f20\u5230\u4f60\u7684\u65b0\u670d\u52a1\u5668\uff1a<\/p>\n

$ ssh-copy-id @ip_address<\/username><\/pre>\n

\u73b0\u5728\uff0c\u4f60\u65e0\u9700\u8f93\u5165\u5bc6\u7801\u5373\u53ef\u767b\u5f55\u5230\u65b0\u670d\u52a1\u5668\u3002<\/p>\n

4\u3001\u5b89\u5168\u5f3a\u5316 SSH<\/strong><\/div>\n

\u63a5\u4e0b\u6765\uff0c\u8fdb\u884c\u4ee5\u4e0b\u4e09\u4e2a\u66f4\u6539\uff1a
\n\u7981\u7528 SSH \u5bc6\u7801\u8ba4\u8bc1
\n\u9650\u5236 root \u8fdc\u7a0b\u767b\u5f55
\n\u9650\u5236\u5bf9 IPv4 \u6216 IPv6 \u7684\u8bbf\u95ee
\n\u4f7f\u7528\u4f60\u9009\u62e9\u7684\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00 \/etc\/ssh\/sshd_config \u5e76\u786e\u4fdd\u4ee5\u4e0b\u884c\uff1a<\/p>\n

\r\nPasswordAuthentication yes\r\nPermitRootLogin yes\r\n<\/pre>\n

\u6539\u6210\u8fd9\u6837\uff1a<\/p>\n

\r\nPasswordAuthentication no\r\nPermitRootLogin no\r\n<\/pre>\n

\u63a5\u4e0b\u6765\uff0c\u901a\u8fc7\u4fee\u6539 AddressFamily \u9009\u9879\u5c06 SSH \u670d\u52a1\u9650\u5236\u4e3a IPv4 \u6216 IPv6\u3002\u8981\u5c06\u5176\u66f4\u6539\u4e3a\u4ec5\u4f7f\u7528 IPv4\uff08\u5bf9\u5927\u591a\u6570\u4eba\u6765\u8bf4\u5e94\u8be5\u6ca1\u95ee\u9898\uff09\uff0c\u8bf7\u8fdb\u884c\u4ee5\u4e0b\u66f4\u6539\uff1a<\/p>\n

AddressFamily inet<\/pre>\n

\u91cd\u65b0\u542f\u52a8 SSH \u670d\u52a1\u4ee5\u542f\u7528\u4f60\u7684\u66f4\u6539\u3002\u8bf7\u6ce8\u610f\uff0c\u5728\u91cd\u65b0\u542f\u52a8 SSH \u670d\u52a1\u4e4b\u524d\uff0c\u4e0e\u670d\u52a1\u5668\u5efa\u7acb\u4e24\u4e2a\u6d3b\u52a8\u8fde\u63a5\u662f\u4e00\u4e2a\u597d\u4e3b\u610f\u3002\u6709\u4e86\u8fd9\u4e9b\u989d\u5916\u7684\u8fde\u63a5\uff0c\u4f60\u53ef\u4ee5\u5728\u91cd\u65b0\u542f\u52a8 SSH \u670d\u52a1\u51fa\u9519\u7684\u60c5\u51b5\u4e0b\u4fee\u590d\u6240\u6709\u95ee\u9898\u3002
\n\u5728 Ubuntu \u4e0a\uff1a<\/p>\n

$ sudo service sshd restart<\/pre>\n

\u5728 Fedora \u6216 CentOS \u6216\u4efb\u4f55\u4f7f\u7528 Systemd \u7684\u7cfb\u7edf\u4e0a\uff1a<\/p>\n

$ sudo systemctl restart sshd<\/pre>\n
5\u3001\u542f\u7528\u9632\u706b\u5899<\/strong><\/div>\n

\u73b0\u5728\uff0c\u4f60\u9700\u8981\u5b89\u88c5\u9632\u706b\u5899\u3001\u542f\u7528\u9632\u706b\u5899\u5e76\u5bf9\u5176\u8fdb\u884c\u914d\u7f6e\uff0c\u4ee5\u4ec5\u5141\u8bb8\u4f60\u6307\u5b9a\u7684\u7f51\u7edc\u6d41\u91cf\u901a\u8fc7\u3002\uff08Ubuntu \u4e0a\u7684\uff09\u7b80\u5355\u7684\u9632\u706b\u5899\uff08UFW\uff09\u662f\u4e00\u4e2a\u6613\u7528\u7684 iptables \u754c\u9762\uff0c\u53ef\u5927\u5927\u7b80\u5316\u9632\u706b\u5899\u7684\u914d\u7f6e\u8fc7\u7a0b\u3002<\/p>\n

\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5b89\u88c5 UFW\uff1a<\/p>\n

$ sudo apt install ufw<\/pre>\n

\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cUFW \u62d2\u7edd\u6240\u6709\u4f20\u5165\u8fde\u63a5\uff0c\u5e76\u5141\u8bb8\u6240\u6709\u4f20\u51fa\u8fde\u63a5\u3002\u8fd9\u610f\u5473\u7740\u670d\u52a1\u5668\u4e0a\u7684\u4efb\u4f55\u5e94\u7528\u7a0b\u5e8f\u90fd\u53ef\u4ee5\u8bbf\u95ee\u4e92\u8054\u7f51\uff0c\u4f46\u662f\u4efb\u4f55\u5c1d\u8bd5\u8bbf\u95ee\u670d\u52a1\u5668\u7684\u5185\u5bb9\u90fd\u65e0\u6cd5\u8fde\u63a5\u3002
\n\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u53ef\u4ee5\u901a\u8fc7\u542f\u7528\u5bf9 SSH\u3001HTTP \u548c HTTPS \u7684\u8bbf\u95ee\u6765\u767b\u5f55\uff1a<\/p>\n

\r\n$ sudo ufw allow ssh\r\n$ sudo ufw allow http\r\n$ sudo ufw allow https\r\n<\/pre>\n

\u7136\u540e\u542f\u7528 UFW\uff1a<\/p>\n

$ sudo ufw enable<\/pre>\n

\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u67e5\u770b\u5141\u8bb8\u548c\u62d2\u7edd\u4e86\u54ea\u4e9b\u670d\u52a1\uff1a<\/p>\n

$ sudo ufw status<\/pre>\n

\u5982\u679c\u4f60\u60f3\u7981\u7528 UFW\uff0c\u53ef\u4ee5\u901a\u8fc7\u952e\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u7981\u7528\uff1a<\/p>\n

$ sudo ufw disable<\/pre>\n

\u4f60\u8fd8\u53ef\u4ee5\uff08\u5728 RHEL\/CentOS \u4e0a\uff09\u4f7f\u7528 firewall-cmd\uff0c\u5b83\u5df2\u7ecf\u5b89\u88c5\u5e76\u96c6\u6210\u5230\u67d0\u4e9b\u53d1\u884c\u7248\u4e2d\u3002<\/p>\n

6\u3001\u5b89\u88c5 Fail2ban<\/strong><\/div>\n

Fail2ban \u662f\u4e00\u79cd\u7528\u4e8e\u68c0\u67e5\u670d\u52a1\u5668\u65e5\u5fd7\u4ee5\u67e5\u627e\u91cd\u590d\u6216\u81ea\u52a8\u653b\u51fb\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u5982\u679c\u627e\u5230\u4efb\u4f55\u653b\u51fb\uff0c\u5b83\u4f1a\u66f4\u6539\u9632\u706b\u5899\u4ee5\u6c38\u4e45\u5730\u6216\u5728\u6307\u5b9a\u7684\u65f6\u95f4\u5185\u963b\u6b62\u653b\u51fb\u8005\u7684 IP \u5730\u5740\u3002
\n\u4f60\u53ef\u4ee5\u901a\u8fc7\u952e\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5 Fail2ban\uff1a<\/p>\n

$ sudo apt install fail2ban -y<\/pre>\n

\u7136\u540e\u590d\u5236\u968f\u9644\u7684\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n

$ sudo cp \/etc\/fail2ban\/jail.conf \/etc\/fail2ban\/jail.local<\/pre>\n

\u91cd\u542f Fail2ban\uff1a<\/p>\n

$ sudo service fail2ban restart<\/pre>\n

\u8fd9\u6837\u5c31\u884c\u4e86\u3002\u8be5\u8f6f\u4ef6\u5c06\u4e0d\u65ad\u68c0\u67e5\u65e5\u5fd7\u6587\u4ef6\u4ee5\u67e5\u627e\u653b\u51fb\u3002\u4e00\u6bb5\u65f6\u95f4\u540e\uff0c\u8be5\u5e94\u7528\u7a0b\u5e8f\u5c06\u5efa\u7acb\u76f8\u5f53\u591a\u7684\u5c01\u7981\u7684 IP \u5730\u5740\u5217\u8868\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u67e5\u8be2 SSH \u670d\u52a1\u7684\u5f53\u524d\u72b6\u6001\u6765\u67e5\u770b\u6b64\u5217\u8868\uff1a<\/p>\n

$ sudo fail2ban-client status ssh<\/pre>\n
7\u3001\u79fb\u9664\u65e0\u7528\u7684\u7f51\u7edc\u670d\u52a1<\/strong><\/div>\n

\u51e0\u4e4e\u6240\u6709 Linux \u670d\u52a1\u5668\u64cd\u4f5c\u7cfb\u7edf\u90fd\u542f\u7528\u4e86\u4e00\u4e9b\u9762\u5411\u7f51\u7edc\u7684\u670d\u52a1\u3002\u4f60\u53ef\u80fd\u5e0c\u671b\u4fdd\u7559\u5176\u4e2d\u5927\u591a\u6570\uff0c\u7136\u800c\uff0c\u6709\u4e00\u4e9b\u4f60\u6216\u8bb8\u5e0c\u671b\u5220\u9664\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 ss \u547d\u4ee4\u67e5\u770b\u6240\u6709\u6b63\u5728\u8fd0\u884c\u7684\u7f51\u7edc\u670d\u52a1\uff1a\uff08LCTT \u8bd1\u6ce8\uff1a\u5e94\u8be5\u662f\u53ea\u4fdd\u7559\u5c11\u90e8\u5206\uff0c\u800c\u6240\u6709\u786e\u8ba4\u65e0\u5173\u7684\u3001\u65e0\u7528\u7684\u670d\u52a1\u90fd\u5e94\u8be5\u505c\u7528\u6216\u5220\u9664\u3002\uff09<\/p>\n

$ sudo ss -atpu<\/pre>\n

ss \u7684\u8f93\u51fa\u53d6\u51b3\u4e8e\u4f60\u7684\u64cd\u4f5c\u7cfb\u7edf\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5b83\u663e\u793a SSH\uff08sshd\uff09\u548c Ngnix\uff08nginx\uff09\u670d\u52a1\u6b63\u5728\u4fa6\u542c\u7f51\u7edc\u5e76\u51c6\u5907\u8fde\u63a5\uff1a<\/p>\n

\r\ntcp LISTEN 0 128 *:http *:* users:((\"nginx\",pid=22563,fd=7))\r\ntcp LISTEN 0 128 *:ssh *:* users:((\"sshd\",pid=685,fd=3))\r\n<\/pre>\n

\u5220\u9664\u672a\u4f7f\u7528\u7684\u670d\u52a1\u7684\u65b9\u5f0f\u56e0\u4f60\u7684\u64cd\u4f5c\u7cfb\u7edf\u53ca\u5176\u4f7f\u7528\u7684\u7a0b\u5e8f\u5305\u7ba1\u7406\u5668\u800c\u5f02\u3002
\n\u8981\u5728 Debian \/ Ubuntu \u4e0a\u5220\u9664\u672a\u4f7f\u7528\u7684\u670d\u52a1\uff1a<\/p>\n

$ sudo apt purge <\/service_name><\/pre>\n

\u8981\u5728 Red Hat\/CentOS \u4e0a\u5220\u9664\u672a\u4f7f\u7528\u7684\u670d\u52a1\uff1a<\/p>\n

$ sudo yum remove <\/service_name><\/pre>\n

\u518d\u6b21\u8fd0\u884c ss -atup \u4ee5\u786e\u8ba4\u8fd9\u4e9b\u672a\u4f7f\u7528\u7684\u670d\u52a1\u6ca1\u6709\u5b89\u88c5\u548c\u8fd0\u884c\u3002<\/p>\n

\u603b\u7ed3<\/strong><\/div>\n

\u672c\u6559\u7a0b\u4ecb\u7ecd\u4e86\u52a0\u56fa Linux \u670d\u52a1\u5668\u6240\u9700\u7684\u6700\u8d77\u7801\u7684\u63aa\u65bd\u3002\u4f60\u5e94\u8be5\u6839\u636e\u670d\u52a1\u5668\u7684\u4f7f\u7528\u65b9\u5f0f\u542f\u7528\u5176\u4ed6\u5b89\u5168\u5c42\u3002\u8fd9\u4e9b\u5b89\u5168\u5c42\u53ef\u4ee5\u5305\u62ec\u8bf8\u5982\u5404\u4e2a\u5e94\u7528\u7a0b\u5e8f\u914d\u7f6e\u3001\u5165\u4fb5\u68c0\u6d4b\u8f6f\u4ef6\uff08IDS\uff09\u4ee5\u53ca\u542f\u7528\u8bbf\u95ee\u63a7\u5236\uff08\u4f8b\u5982\uff0c\u53cc\u56e0\u7d20\u8eab\u4efd\u9a8c\u8bc1\uff09\u4e4b\u7c7b\u7684\u4e1c\u897f\u3002<\/p>\n

via: https:\/\/opensource.com\/article\/19\/10\/linux-server-security<\/p>\n

\u4f5c\u8005\uff1aPatrick H. Mullins \u9009\u9898\uff1alujun9972 \u8bd1\u8005\uff1awxy \u6821\u5bf9\uff1awxy<\/p>\n

\u672c\u6587\u7531 LCTT \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd \u8363\u8a89\u63a8\u51fa<\/p>\n","protected":false},"excerpt":{"rendered":"

\u4fdd\u62a4\u670d\u52a1\u5668\u5b89\u5168\u7684\u7b2c\u4e00\u4ef6\u4e8b\u662f\u66f4\u65b0\u672c\u5730\u5b58\u50a8\u5e93\uff0c\u5e76\u901a\u8fc7\u5e94\u7528\u6700\u65b0\u7684\u4fee\u8865\u7a0b\u5e8f\u6765\u5347\u7ea7\u64cd\u4f5c\u7cfb\u7edf\u548c\u5df2\u5b89\u88c5\u7684\u5e94\u7528\u7a0b\u5e8f\u3002 \u5728 Ub […]<\/p>\n","protected":false},"author":1920,"featured_media":161079,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-161077","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/161077","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1920"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=161077"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/161077\/revisions"}],"predecessor-version":[{"id":161222,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/161077\/revisions\/161222"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/161079"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=161077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=161077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=161077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}