{"id":240001,"date":"2022-04-27T10:23:17","date_gmt":"2022-04-27T02:23:17","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=240001"},"modified":"2022-04-11T11:15:45","modified_gmt":"2022-04-11T03:15:45","slug":"power-linux-sudo","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/power-linux-sudo.html","title":{"rendered":"\u5a01\u529b\u5f3a\u5927\u7684Linux sudo \u547d\u4ee4"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nLinux \u7684\u65b0\u7528\u6237\uff08\u5c24\u5176\u662f Ubuntu\uff09\u5e94\u8be5\u90fd\u4f1a\u5230 sudo \u547d\u4ee4\u3002\u5bf9\u4e8e sudo \u547d\u4ee4\uff0c\u5927\u90e8\u5206\u7528\u6237\u8fc7\u53bb\u9664\u4e86\u89e3\u51b3\u201c\u6743\u9650\u4e0d\u591f\u201d\u6d88\u606f\u5916\uff0c\u4ece\u672a\u5c06\u5b83\u7528\u4e8e\u5176\u4ed6\u4efb\u4f55\u4e8b\u60c5\uff0c\u4f46\u5b9e\u9645\u60c5\u51b5\u662f sudo \u53ef\u4ee5\u505a\u5f97\u66f4\u591a\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u5173\u4e8esudo<\/strong><\/div>\n

\u5173\u4e8e sudo \u7684\u4e00\u4e2a\u5e38\u89c1\u8bef\u89e3\u662f\u5b83\u4ec5\u7528\u4e8e\u4e3a\u666e\u901a\u7528\u6237\u63d0\u4f9b root \u6743\u9650\u3002\u4e8b\u5b9e\u4e0a\uff0csudo \u547d\u4ee4\u5141\u8bb8\u4f60\u4ee5\u4efb\u4f55\u7528\u6237\u8eab\u4efd\u8fd0\u884c\u547d\u4ee4\uff0c\u9ed8\u8ba4\u901a\u5e38\u662f root\u3002<\/p>\n

Linux \u4e2d\u7684 sudo \u547d\u4ee4\u4ee3\u8868Super User DO\u3002\u5b83\u5141\u8bb8\u4f60\u4ee5\u53e6\u4e00\u4e2a\u7528\u6237\uff08\u5305\u62ec\u8d85\u7ea7\u7528\u6237\uff09\u7684\u8eab\u4efd\u6267\u884c\u547d\u4ee4\u3002sudo \u662f\u8bbf\u95ee root \u6743\u9650\u5e76\u4ee5 root \u7528\u6237\u8eab\u4efd\u6267\u884c\u547d\u4ee4\u7684\u6709\u6548\u65b9\u6cd5\u3002\u4f7f\u7528 sudo\uff0c\u4f60\u53ef\u4ee5\u5728\u4e0d\u77e5\u9053 root \u5bc6\u7801\u6216\u4ee5 root \u7528\u6237\u8eab\u4efd\u767b\u5f55\u7684\u60c5\u51b5\u4e0b\u8bbf\u95ee root \u6743\u9650\u3002\u7528\u6237\u9700\u8981\u5177\u6709 sudo \u6743\u9650\u624d\u80fd\u8fd0\u884c\u8be5sudo\u547d\u4ee4\u3002<\/p>\n

\u5982\u4f55\u6388\u4e88\u7528\u6237 sudo \u6743\u9650<\/strong><\/div>\n

Ubuntu \u7528\u6237\u901a\u5e38\u8ba4\u4e3a\u80fd\u591f\u8fd0\u884c sudo \u547d\u4ee4\u662f\u7406\u6240\u5f53\u7136\u7684\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u521b\u5efa\u4e00\u4e2a\u9ed8\u8ba4\u7528\u6237\uff0c\u5e76\u4e14 Ubuntu \u4e2d\u7684\u9ed8\u8ba4\u7528\u6237\u59cb\u7ec8\u8bbe\u7f6e\u6709 sudo \u6743\u9650\u3002\u4f46\u662f\uff0c\u5982\u679c\u4f60\u5728 Ubuntu \u4e2d\u4f7f\u7528\u5176\u4ed6\u53d1\u884c\u7248\u6216\u6709\u5176\u4ed6\u7528\u6237\uff0c\u5219\u53ef\u80fd\u9700\u8981\u6388\u4e88\u7528\u6237\u8fd0\u884c sudo \u547d\u4ee4\u7684\u6743\u9650\u3002<\/p>\n

\u53ea\u6709\u5c11\u6570\u4eba\u5e94\u8be5\u53ef\u4ee5\u8bbf\u95ee sudo \u547d\u4ee4\uff0c\u5e76\u4e14\u4ed6\u4eec\u5e94\u8be5\u662f\u7cfb\u7edf\u7ba1\u7406\u5458\u3002\u7528\u6237\u5e94\u8be5\u53ea\u88ab\u6388\u4e88\u4ed6\u4eec\u6267\u884c\u5de5\u4f5c\u6240\u9700\u7684\u6743\u9650\u3002<\/p>\n

\u8981\u6388\u4e88\u7528\u6237 sudo \u6743\u9650\uff0c\u4f60\u53ea\u9700\u5c06\u4ed6\u4eec\u6dfb\u52a0\u5230 sudo \u7ec4\u3002\u521b\u5efa\u7528\u6237\u65f6\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

sudo usermod -a -G sudo ubuntu<\/pre>\n

\"\"<\/p>\n

\u4e0a\u8ff0\u547d\u4ee4\u5c06\u521b\u5efa\u4e00\u4e2a\u5177\u6709\u4e3b\u6587\u4ef6\u5939\u7684\u7528\u6237\u5e76\u5c06\u8be5\u7528\u6237\u6dfb\u52a0\u5230 sudo \u7ec4\u3002\u5982\u679c\u7528\u6237\u5df2\u7ecf\u5b58\u5728\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5c06\u7528\u6237\u6dfb\u52a0\u5230 sudo \u7ec4\uff1a<\/p>\n

sudo usermod -a -G sudo linux<\/pre>\n

\"\"<\/p>\n

\u5f53\u4f60\u5fd8\u8bb0\u8fd0\u884c\u5b83\u65f6\u4e00\u4e2a\u5de7\u5999\u7684 sudo \u6280\u5de7<\/strong><\/div>\n

\u4e0b\u9762\u662f\u4f60\u53ef\u4ee5\u4ece\u7ecf\u9a8c\u4e30\u5bcc\u7684\u4e13\u5bb6\u90a3\u91cc\u5b66\u5230\u7684\u4e00\u79cd\u7ec8\u7aef\u547d\u4ee4\u6280\u5de7\uff0c\u5728\u672c\u4f8b\u4e2d\uff0c\u7528\u4e8e\u901a\u8fc7\u201c\u6743\u9650\u4e0d\u591f\u201d\u6d88\u606f\u3002\u5982\u679c\u8fd9\u662f\u4e00\u4e2a\u5f88\u957f\u7684\u547d\u4ee4\uff0c\u4f60\u53ef\u4ee5\u5728\u5386\u53f2\u8bb0\u5f55\u4e2d\u628a sudo \u653e\u5728\u524d\u9762\uff0c\u53ef\u4ee5\u518d\u6253\u51fa\u6765\uff0c\u4e5f\u53ef\u4ee5\u7528\u4e0b\u9762\u8fd9\u4e2a\u7b80\u5355\u7684\u547d\u4ee4\uff0c\u7528 sudo \u8fd0\u884c\u524d\u9762\u7684\u547d\u4ee4\uff1a<\/p>\n

sudo !!<\/pre>\n

\"\"<\/p>\n

bang bang (!!)\u547d\u4ee4\u662f\u91cd\u590d\u548c\u8fd0\u884c\u60a8\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u7684\u4e0a\u4e00\u4e2a\u547d\u4ee4\u7684\u5feb\u6377\u65b9\u5f0f\u3002\u5f53\u60a8\u5fd8\u8bb0\u9700\u8981\u7ba1\u7406\u5458\u6743\u9650\u624d\u80fd\u6267\u884c\u67d0\u9879\u64cd\u4f5c\u65f6\uff0c\u6b64\u547d\u4ee4\u975e\u5e38\u6709\u7528\uff0c\u5e76\u4e14\u53ea\u9700\u952e\u5165\u5373\u53ef\u4f7f\u7528super-user\u6743\u9650\u91cd\u590d\u6b64\u547d\u4ee4\uff0c!!\u83b7\u53d6\u6700\u540e\u4e00\u6b21\u8fd0\u884c\u547d\u4ee4\u3002<\/p>\n

\u5982\u4f55\u901a\u8fc7 sudo \u5207\u6362\u5230 root \u7528\u6237<\/strong><\/div>\n

su \u547d\u4ee4\u7528\u4e8e\u4ece\u4e00\u4e2a\u7528\u6237\u5e10\u6237\u5207\u6362\u5230\u53e6\u4e00\u4e2a\u7528\u6237\u5e10\u6237\u3002\u5728\u81ea\u5df1\u7684\u4ea4\u6362\u673a\u4e0a\u8fd0\u884cSu\u547d\u4ee4\u5230\u8d85\u7ea7\u7528\u6237\u5e10\u6237\u3002\u56e0\u6b64\uff0c\u4f7f\u7528 sudo \u547d\u4ee4\u5207\u6362\u5230\u8d85\u7ea7\u7528\u6237\uff0c\u53ea\u9700\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4:<\/p>\n

sudo su<\/pre>\n

\"\"<\/p>\n

\u5982\u4f55\u5728\u540e\u53f0\u8fd0\u884c sudo \u547d\u4ee4<\/strong><\/div>\n

\u5982\u679c\u8981\u5728\u540e\u53f0\u8fd0\u884c\u9700\u8981\u8d85\u7ea7\u7528\u6237\u6743\u9650\u7684\u547d\u4ee4\uff0c\u8bf7\u4f7f\u7528 -b \u5f00\u5173\u8fd0\u884c sudo \u547d\u4ee4\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

sudo -b \u547d\u4ee4<\/pre>\n

\u8bf7\u6ce8\u610f\uff0c\u5982\u679c\u6b63\u5728\u8fd0\u884c\u7684\u547d\u4ee4\u9700\u8981\u7528\u6237\u4ea4\u4e92\uff0c\u8fd9\u5c06\u4e0d\u8d77\u4f5c\u7528\u3002<\/p>\n

\u5728\u540e\u53f0\u8fd0\u884c\u547d\u4ee4\u7684\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u5728\u672b\u5c3e\u6dfb\u52a0\u4e00\u4e2a & \u7b26\u53f7\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

sudo & \u547d\u4ee4<\/pre>\n

\"\"<\/p>\n

\u5982\u4f55\u4f7f\u7528 sudo \u6743\u9650\u7f16\u8f91\u6587\u4ef6<\/strong><\/div>\n

\u4f7f\u7528\u8d85\u7ea7\u7528\u6237\u6743\u9650\u7f16\u8f91\u6587\u4ef6\u7684\u660e\u663e\u65b9\u6cd5\u662f\u8fd0\u884c\u7f16\u8f91\u5668\uff0c\u4f8b\u5982GNU nano\uff0c \u4f7f\u7528 sudo \u5982\u4e0b\uff1a<\/p>\n

sudo nano<\/pre>\n

\u6216\u8005\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n

sudo -e<\/pre>\n
\u5982\u4f55\u4f7f\u7528 sudo \u4ee5\u5176\u4ed6\u7528\u6237\u8eab\u4efd\u8fd0\u884c\u547d\u4ee4<\/strong><\/div>\n

sudo \u547d\u4ee4\u53ef\u7528\u4e8e\u4ee5\u4efb\u4f55\u5176\u4ed6\u7528\u6237\u8eab\u4efd\u8fd0\u884c\u547d\u4ee4\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u4ee5\u7528\u6237\u201clinuxmi\u201d\u8eab\u4efd\u767b\u5f55\uff0c\u5e76\u4e14\u5e0c\u671b\u4ee5\u201clinux\u201d\u8eab\u4efd\u8fd0\u884c\u8be5\u547d\u4ee4\uff0c\u90a3\u4e48\u4f60\u5c06\u6309\u4ee5\u4e0b\u65b9\u5f0f\u8fd0\u884c sudo \u547d\u4ee4\uff1a<\/p>\n

sudo -u<\/pre>\n

\"\"<\/p>\n

\u5982\u679c\u4f60\u60f3\u5c1d\u8bd5\u4e00\u4e0b\uff0c\u8bf7\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201clinux\u201d\u7684\u65b0\u7528\u6237\uff0c\u5e76\u8fd0\u884c\u4ee5\u4e0bWhoami \u547d\u4ee4\uff1a<\/p>\n

sudo -u linux whoami<\/pre>\n

\"\"<\/p>\n

\u5982\u4f55\u9a8c\u8bc1 sudo \u51ed\u636e<\/strong><\/div>\n

\u5f53\u4f60\u4f7f\u7528 sudo \u8fd0\u884c\u547d\u4ee4\u65f6\uff0c\u7cfb\u7edf\u4f1a\u63d0\u793a\u4f60\u8f93\u5165\u5bc6\u7801\u3002\u4e00\u6bb5\u65f6\u95f4\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 sudo \u8fd0\u884c\u5176\u4ed6\u547d\u4ee4\uff0c\u800c\u65e0\u9700\u8f93\u5165\u5bc6\u7801\u3002\u5982\u679c\u4f60\u5e0c\u671b\u5ef6\u957f\u8be5\u671f\u9650\uff0c\u8bf7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

sudo -v<\/pre>\n

\u4f7f\u7528 sudo \u547d\u4ee4\u5217\u51fa\u7528\u6237\u6743\u9650<\/p>\n

-l \u6216\u8005\u2013list \u9009\u9879\u7528\u4e8e\u5217\u51fa\u7528\u6237\u5bf9\u8f93\u51fa\u7684\u6743\u9650\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u6b64\u9009\u9879\u4e24\u6b21\u4ee5\u83b7\u5f97\u66f4\u957f\u7684\u683c\u5f0f\u3002<\/p>\n

sudo -l\r\n\u6216\u8005\r\nsudo --list<\/pre>\n

\u4f7f\u7528\u4e24\u6b21 -l \u4ee5\u83b7\u5f97\u66f4\u957f\u7684\u8f93\u51fa\uff1a<\/p>\n

sudo -ll<\/pre>\n

\"\"<\/p>\n

\u4f7f\u7528 sudo \u547d\u4ee4\u663e\u793a\u53e6\u4e00\u4e2a\u7528\u6237\u7684\u6743\u9650<\/strong><\/div>\n

\u60a8\u53ef\u4ee5\u4f7f\u7528 -U \u6216\u2013other-user \u9009\u9879 -l \u6765\u663e\u793a\u7ed9\u5b9a\u7528\u6237\u7684\u7528\u6237\u6743\u9650\u3002<\/p>\n

 sudo -l -U linux\r\n\u6216\u8005\r\nsudo -l  --other-user linux<\/pre>\n

\"\"<\/p>\n

\u66f4\u591a\u5173\u4e8e sudo<\/strong><\/div>\n

\nsudo \u4e0d\u4ec5\u4ec5\u662f\u4ee5\u8d85\u7ea7\u7528\u6237\u8eab\u4efd\u8fd0\u884c\u547d\u4ee4\u3002\u67e5\u770b\u6211\u4eec\u7684 sudo \u624b\u518c\uff0c\u4e86\u89e3\u4f60\u53ef\u4ee5\u4f7f\u7528\u7684\u5176\u4ed6\u4e00\u4e9b\u9009\u9879\u3002<\/p>\n<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"

\u5173\u4e8e sudo \u7684\u4e00\u4e2a\u5e38\u89c1\u8bef\u89e3\u662f\u5b83\u4ec5\u7528\u4e8e\u4e3a\u666e\u901a\u7528\u6237\u63d0\u4f9b root \u6743\u9650\u3002\u4e8b\u5b9e\u4e0a\uff0csudo \u547d\u4ee4\u5141\u8bb8\u4f60\u4ee5\u4efb\u4f55\u7528\u6237 […]<\/p>\n","protected":false},"author":310,"featured_media":240050,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-240001","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\/240001","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\/310"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=240001"}],"version-history":[{"count":27,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/240001\/revisions"}],"predecessor-version":[{"id":240555,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/240001\/revisions\/240555"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/240050"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=240001"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=240001"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=240001"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}