{"id":63289,"date":"2025-04-29T10:40:37","date_gmt":"2025-04-29T02:40:37","guid":{"rendered":"https:\/\/fwq.ai\/blog\/63289\/"},"modified":"2025-04-29T10:40:37","modified_gmt":"2025-04-29T02:40:37","slug":"linux%e7%b3%bb%e7%bb%9f%e4%b8%ad%e7%9a%84%e7%94%a8%e6%88%b7%e5%af%86%e7%a0%81%e5%ad%98%e5%82%a8%e6%9c%ba%e5%88%b6%e8%a7%a3%e6%9e%90-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/63289\/","title":{"rendered":"Linux\u7cfb\u7edf\u4e2d\u7684\u7528\u6237\u5bc6\u7801\u5b58\u50a8\u673a\u5236\u89e3\u6790"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/171092322499062.jpg\" class=\"aligncenter\" title=\"Linux\u7cfb\u7edf\u4e2d\u7684\u7528\u6237\u5bc6\u7801\u5b58\u50a8\u673a\u5236\u89e3\u6790\u63d2\u56fe\" alt=\"Linux\u7cfb\u7edf\u4e2d\u7684\u7528\u6237\u5bc6\u7801\u5b58\u50a8\u673a\u5236\u89e3\u6790\u63d2\u56fe\" \/><\/p>\n<p>Linux\u7cfb\u7edf\u4e2d\u7684\u7528\u6237\u5bc6\u7801\u5b58\u50a8\u673a\u5236\u89e3\u6790<\/p>\n<p>\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u7528\u6237\u5bc6\u7801\u7684\u5b58\u50a8\u662f\u975e\u5e38\u91cd\u8981\u7684\u5b89\u5168\u673a\u5236\u4e4b\u4e00\u3002\u672c\u6587\u5c06\u89e3\u6790Linux\u7cfb\u7edf\u4e2d\u7528\u6237\u5bc6\u7801\u7684\u5b58\u50a8\u673a\u5236\uff0c\u5305\u62ec\u5bc6\u7801\u7684\u52a0\u5bc6\u5b58\u50a8\u3001\u5bc6\u7801\u7684\u9a8c\u8bc1\u8fc7\u7a0b\u4ee5\u53ca\u5982\u4f55\u5b89\u5168\u5730\u7ba1\u7406\u7528\u6237\u5bc6\u7801\u3002\u540c\u65f6\uff0c\u5c06\u901a\u8fc7\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u5c55\u793a\u5bc6\u7801\u5b58\u50a8\u7684\u5b9e\u9645\u64cd\u4f5c\u8fc7\u7a0b\u3002<\/p>\n<p>\u4e00\u3001\u5bc6\u7801\u7684\u52a0\u5bc6\u5b58\u50a8<\/p>\n<p>\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u7528\u6237\u5bc6\u7801\u5e76\u4e0d\u662f\u4ee5\u660e\u6587\u7684\u5f62\u5f0f\u5b58\u50a8\u5728\u7cfb\u7edf\u4e2d\uff0c\u800c\u662f\u7ecf\u8fc7\u52a0\u5bc6\u540e\u4fdd\u5b58\u3002Linux\u7cfb\u7edf\u4e2d\u5e38\u7528\u7684\u5bc6\u7801\u52a0\u5bc6\u7b97\u6cd5\u662fSHA-512\uff08SHA-256\u4e5f\u53ef\u4ee5\u4f7f\u7528\uff09\u3002\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u7528\u6237\u7684\u5bc6\u7801\u5b58\u50a8\u5728\/etc\/shadow\u6587\u4ef6\u4e2d\uff0c\u8be5\u6587\u4ef6\u4e2d\u4fdd\u5b58\u4e86\u7528\u6237\u7684\u8d26\u53f7\u4fe1\u606f\uff0c\u5305\u62ec\u52a0\u5bc6\u540e\u7684\u5bc6\u7801\u3001\u5bc6\u7801\u8fc7\u671f\u65f6\u95f4\u3001\u5bc6\u7801\u6700\u540e\u4fee\u6539\u65f6\u95f4\u7b49\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u7684\/etc\/shadow\u6587\u4ef6\u7684\u5185\u5bb9\uff1a<\/p>\n<pre>root:$6$xld94ij$BW0RfSx9WLNAWia7D5PQwx\/dNnhTgy8f3W6\/vobqEmmhVUISZoL5EwrF8RTXA8xRztRGtUjLzxyBnUqVoJk7Z.:18474:0:99999:7:::\nuser1:$6$du065TO$9v6.LU3F8JbLVQ7FEQEfkrQ.Zd8dxR.Vl5ohZ9uiXG4lF8k1OHkRTrqtzc5RpaC2mvM5KpIe7YH2zUL3MOUEO1:18474:0:99999:7:::<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5176\u4e2d\uff0c\u7b2c\u4e00\u4e2a\u5b57\u6bb5\u8868\u793a\u7528\u6237\u540d\uff0c\u7b2c\u4e8c\u4e2a\u5b57\u6bb5\u662f\u52a0\u5bc6\u540e\u7684\u5bc6\u7801\u3002\u53ef\u4ee5\u770b\u5230\uff0c\u5bc6\u7801\u5df2\u7ecf\u88ab\u52a0\u5bc6\u6210\u4e00\u6bb5\u4e71\u7801\uff0c\u8fd9\u6837\u5373\u4f7f\/etc\/shadow\u6587\u4ef6\u88ab\u6cc4\u9732\uff0c\u9ed1\u5ba2\u4e5f\u5f88\u96be\u8fd8\u539f\u51fa\u7528\u6237\u7684\u5bc6\u7801\u3002<\/p>\n<p>\u4e8c\u3001\u5bc6\u7801\u7684\u9a8c\u8bc1\u8fc7\u7a0b<\/p>\n<p>\u5f53\u7528\u6237\u767b\u5f55\u7cfb\u7edf\u65f6\uff0c\u7cfb\u7edf\u4f1a\u9a8c\u8bc1\u7528\u6237\u8f93\u5165\u7684\u5bc6\u7801\u662f\u5426\u6b63\u786e\u3002\u9a8c\u8bc1\u5bc6\u7801\u7684\u8fc7\u7a0b\u5b9e\u9645\u4e0a\u5c31\u662f\u5c06\u7528\u6237\u8f93\u5165\u7684\u5bc6\u7801\u6309\u7167\u76f8\u540c\u7684\u52a0\u5bc6\u7b97\u6cd5\u8fdb\u884c\u52a0\u5bc6\uff0c\u7136\u540e\u548c\/etc\/shadow\u6587\u4ef6\u4e2d\u7684\u5bc6\u7801\u8fdb\u884c\u6bd4\u5bf9\u3002\u5982\u679c\u4e24\u8005\u4e00\u81f4\uff0c\u5219\u9a8c\u8bc1\u6210\u529f\uff0c\u5141\u8bb8\u7528\u6237\u767b\u5f55\uff1b\u5426\u5219\u9a8c\u8bc1\u5931\u8d25\uff0c\u62d2\u7edd\u7528\u6237\u767b\u5f55\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5bc6\u7801\u9a8c\u8bc1\u7684\u4ee3\u7801\u793a\u4f8b\uff0c\u4f7f\u7528Python\u7f16\u5199\uff1a<\/p>\n<pre>import crypt\nimport getpass\n\ndef validate_password(username, password):\n    with open('\/etc\/shadow', 'r') as f:\n        for line in f:\n            if line.startswith(username + ':'):\n                shadow_entry = line.split(':')\n                encrypted_password = shadow_entry[1]\n                salt = encrypted_password.split('$')[2]\n                new_encrypted_password = crypt.crypt(password, '$6$' + salt + '$')\n                if new_encrypted_password == encrypted_password:\n                    return True\n                else:\n                    return False\n    return False\n\nusername = input(\"Enter username: \")\npassword = getpass.getpass(\"Enter password: \")\n\nif validate_password(username, password):\n    print(\"Password is correct. Logging in...\")\nelse:\n    print(\"Password is incorrect. Please try again.\")<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e09\u3001\u5b89\u5168\u5730\u7ba1\u7406\u7528\u6237\u5bc6\u7801<\/p>\n<p>\u7ba1\u7406\u7528\u6237\u5bc6\u7801\u662f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u5b89\u5168\u95ee\u9898\u3002\u9996\u5148\uff0c\u5e94\u8be5\u907f\u514d\u4f7f\u7528\u7b80\u5355\u5bc6\u7801\uff0c\u63a8\u8350\u4f7f\u7528\u5305\u542b\u5927\u5c0f\u5199\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u7279\u6b8a\u5b57\u7b26\u7684\u590d\u6742\u5bc6\u7801\u3002\u5176\u6b21\uff0c\u5b9a\u671f\u4fee\u6539\u5bc6\u7801\uff0c\u907f\u514d\u4f7f\u7528\u540c\u4e00\u4e2a\u5bc6\u7801\u957f\u65f6\u95f4\u4e0d\u53d8\u3002\u53e6\u5916\uff0c\u4e0d\u5e94\u8be5\u5c06\u5bc6\u7801\u660e\u6587\u5b58\u50a8\u5728\u4efb\u4f55\u5730\u65b9\uff0c\u5305\u62ec\u4ee3\u7801\u4e2d\u3002<\/p>\n<p>\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u7ba1\u7406\u5458\u53ef\u4ee5\u4f7f\u7528passwd\u547d\u4ee4\u6765\u4fee\u6539\u7528\u6237\u5bc6\u7801\uff0c\u8be5\u547d\u4ee4\u4f1a\u81ea\u52a8\u5c06\u7528\u6237\u5bc6\u7801\u52a0\u5bc6\u540e\u5b58\u50a8\u5230\/etc\/shadow\u6587\u4ef6\u4e2d\u3002\u53e6\u5916\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u4e13\u95e8\u7684\u5bc6\u7801\u7ba1\u7406\u5de5\u5177\u6765\u5e2e\u52a9\u7ba1\u7406\u7528\u6237\u7684\u5bc6\u7801\uff0c\u5982KeePass\u3001LastPass\u7b49\u3002<\/p>\n<p>\u603b\u7ed3\uff1a<br \/>Linux\u7cfb\u7edf\u4e2d\u7684\u7528\u6237\u5bc6\u7801\u5b58\u50a8\u673a\u5236\u662f\u975e\u5e38\u91cd\u8981\u7684\u5b89\u5168\u673a\u5236\uff0c\u901a\u8fc7\u52a0\u5bc6\u5b58\u50a8\u548c\u4e25\u683c\u7684\u9a8c\u8bc1\u8fc7\u7a0b\uff0c\u4fdd\u62a4\u4e86\u7528\u6237\u5bc6\u7801\u4e0d\u88ab\u8f7b\u6613\u6cc4\u9732\u3002\u7ba1\u7406\u5458\u9700\u8981\u5b9a\u671f\u5ba1\u67e5\u5bc6\u7801\u7b56\u7565\uff0c\u786e\u4fdd\u7528\u6237\u5bc6\u7801\u7684\u5b89\u5168\u6027\u3002\u540c\u65f6\uff0c\u7528\u6237\u4e5f\u9700\u8981\u6ce8\u610f\u5bc6\u7801\u7684\u5b89\u5168\u6027\uff0c\u907f\u514d\u4f7f\u7528\u7b80\u5355\u5bc6\u7801\u548c\u5c06\u5bc6\u7801\u660e\u6587\u5b58\u50a8\u5728\u4e0d\u5b89\u5168\u7684\u5730\u65b9\u3002<\/p>\n<p>\u901a\u8fc7\u672c\u6587\u7684\u89e3\u6790\u548c\u4ee3\u7801\u793a\u4f8b\uff0c\u5e0c\u671b\u8bfb\u8005\u5bf9Linux\u7cfb\u7edf\u4e2d\u7528\u6237\u5bc6\u7801\u7684\u5b58\u50a8\u673a\u5236\u6709\u66f4\u6df1\u5165\u7684\u4e86\u89e3\uff0c\u4ee5\u63d0\u9ad8\u7cfb\u7edf\u7684\u5b89\u5168\u6027\u3002<\/p>\n<p>\u3010\u5b57\u6570\uff1a798\u5b57\u3011<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fLinux\u7cfb\u7edf\u4e2d\u7684\u7528\u6237\u5bc6\u7801\u5b58\u50a8\u673a\u5236\u89e3\u6790\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8FDCServers\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux\u7cfb\u7edf\u4e2d\u7684\u7528\u6237\u5bc6\u7801\u5b58\u50a8\u673a\u5236\u89e3\u6790 \u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u7528\u6237\u5bc6\u7801\u7684\u5b58\u50a8\u662f\u975e\u5e38\u91cd\u8981\u7684\u5b89\u5168\u673a\u5236\u4e4b\u4e00\u3002\u672c\u6587\u5c06\u89e3\u6790Linux\u7cfb\u7edf\u4e2d\u7528\u6237\u5bc6\u7801\u7684\u5b58\u50a8\u673a\u5236\uff0c\u5305\u62ec\u5bc6\u7801\u7684\u52a0\u5bc6\u5b58\u50a8\u3001\u5bc6\u7801\u7684\u9a8c\u8bc1\u8fc7\u7a0b\u4ee5\u53ca\u5982\u4f55\u5b89\u5168\u5730\u7ba1\u7406\u7528\u6237\u5bc6\u7801\u3002\u540c\u65f6\uff0c\u5c06\u901a\u8fc7\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u5c55\u793a\u5bc6\u7801\u5b58\u50a8\u7684\u5b9e\u9645\u64cd\u4f5c\u8fc7\u7a0b\u3002 \u4e00\u3001\u5bc6\u7801\u7684\u52a0\u5bc6\u5b58\u50a8 \u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u7528\u6237\u5bc6\u7801\u5e76\u4e0d\u662f\u4ee5\u660e\u6587\u7684\u5f62\u5f0f\u5b58\u50a8\u5728\u7cfb\u7edf\u4e2d\uff0c\u800c\u662f\u7ecf\u8fc7\u52a0\u5bc6\u540e\u4fdd\u5b58\u3002Linux\u7cfb\u7edf\u4e2d\u5e38\u7528\u7684\u5bc6\u7801\u52a0\u5bc6\u7b97\u6cd5\u662fSHA-512\uff08SHA-256\u4e5f\u53ef\u4ee5\u4f7f\u7528\uff09\u3002\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u7528\u6237\u7684\u5bc6\u7801\u5b58\u50a8\u5728\/etc\/shadow\u6587\u4ef6\u4e2d\uff0c\u8be5\u6587\u4ef6\u4e2d\u4fdd\u5b58\u4e86\u7528\u6237\u7684\u8d26\u53f7\u4fe1\u606f\uff0c\u5305\u62ec\u52a0\u5bc6\u540e\u7684\u5bc6\u7801\u3001\u5bc6\u7801\u8fc7\u671f\u65f6\u95f4\u3001\u5bc6\u7801\u6700\u540e\u4fee\u6539\u65f6\u95f4\u7b49\u3002 \u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u7684\/etc\/shadow\u6587\u4ef6\u7684\u5185\u5bb9\uff1a root:$6$xld94ij$BW0RfSx9WLNAWia7D5PQwx\/dNnhTgy8f3W6\/vobqEmmhVUISZoL5EwrF8RTXA8xRztRGtUjLzxyBnUqVoJk7Z.:18474:0:99999:7::: user1:$6$du065TO$9v6.LU3F8JbLVQ7FEQEfkrQ.Zd8dxR.Vl5ohZ9uiXG4lF8k1OHkRTrqtzc5RpaC2mvM5KpIe7YH2zUL3MOUEO1:18474:0:99999:7::: \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff0c\u7b2c\u4e00\u4e2a\u5b57\u6bb5\u8868\u793a\u7528\u6237\u540d\uff0c\u7b2c\u4e8c\u4e2a\u5b57\u6bb5\u662f\u52a0\u5bc6\u540e\u7684\u5bc6\u7801\u3002\u53ef\u4ee5\u770b\u5230\uff0c\u5bc6\u7801\u5df2\u7ecf\u88ab\u52a0\u5bc6\u6210\u4e00\u6bb5\u4e71\u7801\uff0c\u8fd9\u6837\u5373\u4f7f\/etc\/shadow\u6587\u4ef6\u88ab\u6cc4\u9732\uff0c\u9ed1\u5ba2\u4e5f\u5f88\u96be\u8fd8\u539f\u51fa\u7528\u6237\u7684\u5bc6\u7801\u3002 \u4e8c\u3001\u5bc6\u7801\u7684\u9a8c\u8bc1\u8fc7\u7a0b \u5f53\u7528\u6237\u767b\u5f55\u7cfb\u7edf\u65f6\uff0c\u7cfb\u7edf\u4f1a\u9a8c\u8bc1\u7528\u6237\u8f93\u5165\u7684\u5bc6\u7801\u662f\u5426\u6b63\u786e\u3002\u9a8c\u8bc1\u5bc6\u7801\u7684\u8fc7\u7a0b\u5b9e\u9645\u4e0a\u5c31\u662f\u5c06\u7528\u6237\u8f93\u5165\u7684\u5bc6\u7801\u6309\u7167\u76f8\u540c\u7684\u52a0\u5bc6\u7b97\u6cd5\u8fdb\u884c\u52a0\u5bc6\uff0c\u7136\u540e\u548c\/etc\/shadow\u6587\u4ef6\u4e2d\u7684\u5bc6\u7801\u8fdb\u884c\u6bd4\u5bf9\u3002\u5982\u679c\u4e24\u8005\u4e00\u81f4\uff0c\u5219\u9a8c\u8bc1\u6210\u529f\uff0c\u5141\u8bb8\u7528\u6237\u767b\u5f55\uff1b\u5426\u5219\u9a8c\u8bc1\u5931\u8d25\uff0c\u62d2\u7edd\u7528\u6237\u767b\u5f55\u3002 \u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5bc6\u7801\u9a8c\u8bc1\u7684\u4ee3\u7801\u793a\u4f8b\uff0c\u4f7f\u7528Python\u7f16\u5199\uff1a import crypt import getpass def validate_password(username, password): with open(&#8216;\/etc\/shadow&#8217;, &#8216;r&#8217;) as f: for line in f: if line.startswith(username + &#8216;:&#8217;): shadow_entry = line.split(&#8216;:&#8217;) encrypted_password = shadow_entry[1] salt = encrypted_password.split(&#8216;$&#8217;)[2] new_encrypted_password = crypt.crypt(password, &#8216;$6$&#8217; + salt + &#8216;$&#8217;) if new_encrypted_password == encrypted_password: return True [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-63289","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=63289"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63289\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=63289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=63289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=63289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}