{"id":204691,"date":"2020-11-16T08:45:54","date_gmt":"2020-11-16T00:45:54","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=204691"},"modified":"2020-11-03T09:05:19","modified_gmt":"2020-11-03T01:05:19","slug":"linux-sudo-config","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-sudo-config.html","title":{"rendered":"\u5206\u4eabLinux\u4e0b\u7684sudo\u53ca\u5176\u914d\u7f6e\u6587\u4ef6\/etc\/sudoers\u8be6\u7ec6\u914d\u7f6e"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86\u8be6\u89e3Linux\u4e0b\u7684sudo\u53ca\u5176\u914d\u7f6e\u6587\u4ef6\/etc\/sudoers\u7684\u8be6\u7ec6\u914d\u7f6e\u7684\u76f8\u5173\u8d44\u6599,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
1.sudo\u4ecb\u7ecd<\/strong><\/div>\n

sudo\u662flinux\u4e0b\u5e38\u7528\u7684\u5141\u8bb8\u666e\u901a\u7528\u6237\u4f7f\u7528\u8d85\u7ea7\u7528\u6237\u6743\u9650\u7684\u5de5\u5177\uff0c\u5141\u8bb8\u7cfb\u7edf\u7ba1\u7406\u5458\u8ba9\u666e\u901a\u7528\u6237\u6267\u884c\u4e00\u4e9b\u6216\u8005\u5168\u90e8\u7684root\u547d\u4ee4\uff0c\u5982halt\uff0creboot\uff0csu\u7b49\u7b49\u3002\u8fd9\u6837\u4e0d\u4ec5\u51cf\u5c11\u4e86root\u7528\u6237\u7684\u767b\u9646 \u548c\u7ba1\u7406\u65f6\u95f4\uff0c\u540c\u6837\u4e5f\u63d0\u9ad8\u4e86\u5b89\u5168\u6027\u3002Sudo\u4e0d\u662f\u5bf9shell\u7684\u4e00\u4e2a\u4ee3\u66ff\uff0c\u5b83\u662f\u9762\u5411\u6bcf\u4e2a\u547d\u4ee4\u7684\u3002<\/p>\n

\u5b83\u7684\u7279\u6027\u4e3b\u8981\u6709\u8fd9\u6837\u51e0\u70b9\uff1a<\/strong><\/span><\/div>\n
  • sudo\u80fd\u591f\u9650\u5236\u7528\u6237\u53ea\u5728\u67d0\u53f0\u4e3b\u673a\u4e0a\u8fd0\u884c\u67d0\u4e9b\u547d\u4ee4\u3002<\/li>\n
  • sudo\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u65e5\u5fd7\uff0c\u8be6\u7ec6\u5730\u8bb0\u5f55\u4e86\u6bcf\u4e2a\u7528\u6237\u5e72\u4e86\u4ec0\u4e48\u3002\u5b83\u80fd\u591f\u5c06\u65e5\u5fd7\u4f20\u5230\u4e2d\u5fc3\u4e3b\u673a\u6216\u8005\u65e5\u5fd7\u670d\u52a1\u5668\u3002<\/li>\n
  • sudo\u4f7f\u7528\u65f6\u95f4\u6233\u6587\u4ef6\u6765\u6267\u884c\u7c7b\u4f3c\u7684\u201c\u68c0\u7968\u201d\u7cfb\u7edf\u3002\u5f53\u7528\u6237\u8c03\u7528sudo\u5e76\u4e14\u8f93\u5165\u5b83\u7684\u5bc6\u7801\u65f6\uff0c\u7528\u6237\u83b7\u5f97\u4e86\u4e00\u5f20\u5b58\u6d3b\u671f\u4e3a5\u5206\u949f\u7684\u7968\uff08\u8fd9\u4e2a\u503c\u53ef\u4ee5\u5728\u7f16\u8bd1\u7684\u65f6\u5019\u6539\u53d8\uff09\u3002<\/li>\n
  • sudo\u7684\u914d\u7f6e\u6587\u4ef6\u662fsudoers\u6587\u4ef6\uff0c\u5b83\u5141\u8bb8\u7cfb\u7edf\u7ba1\u7406\u5458\u96c6\u4e2d\u7684\u7ba1\u7406\u7528\u6237\u7684\u4f7f\u7528\u6743\u9650\u548c\u4f7f\u7528\u7684\u4e3b\u673a\u3002\u5b83\u6240\u5b58\u653e\u7684\u4f4d\u7f6e\u9ed8\u8ba4\u662f\u5728\/etc\/sudoers\uff0c\u5c5e\u6027\u5fc5\u987b\u4e3a0411\u3002<\/li>\n
    2.\u914d\u7f6e\u6587\u4ef6\/etc\/sudoers<\/strong><\/div>\n

    \u5b83\u7684\u4e3b\u8981\u914d\u7f6e\u6587\u4ef6\u662fsudoers,linux\u4e0b\u901a\u5e38\u5728\/etc\u76ee\u5f55\u4e0b\uff0c\u5982\u679c\u662fsolaris\uff0c\u7f3a\u7701\u4e0d\u88c5sudo\u7684\uff0c\u7f16\u8bd1\u5b89\u88c5\u540e\u901a\u5e38\u5728\u5b89\u88c5\u76ee\u5f55\u7684 etc\u76ee\u5f55\u4e0b\uff0c\u4e0d\u8fc7\u4e0d\u7ba1sudoers\u6587\u4ef6\u5728\u54ea\u513f\uff0csudo\u90fd\u63d0\u4f9b\u4e86\u4e00\u4e2a\u7f16\u8f91\u8be5\u6587\u4ef6\u7684\u547d\u4ee4\uff1avisudo\u6765\u5bf9\u8be5\u6587\u4ef6\u8fdb\u884c\u4fee\u6539\u3002\u5f3a\u70c8\u63a8\u8350\u4f7f\u7528\u8be5\u547d\u4ee4\u4fee\u6539 sudoers\uff0c\u56e0\u4e3a\u5b83\u4f1a\u5e2e\u4f60\u6821\u9a8c\u6587\u4ef6\u914d\u7f6e\u662f\u5426\u6b63\u786e\uff0c\u5982\u679c\u4e0d\u6b63\u786e\uff0c\u5728\u4fdd\u5b58\u9000\u51fa\u65f6\u5c31\u4f1a\u63d0\u793a\u4f60\u54ea\u6bb5\u914d\u7f6e\u51fa\u9519\u7684\u3002<\/p>\n

    \u8a00\u5f52\u6b63\u4f20\uff0c\u4e0b\u9762\u4ecb\u7ecd\u5982\u4f55\u914d\u7f6esudoers\u9996\u5148\u5199sudoers\u7684\u7f3a\u7701\u914d\u7f6e\uff1a<\/p>\n

     \r\n############################################################# \r\n# sudoers file. \r\n# \r\n# This file MUST be edited with the 'visudo' command as root. \r\n# \r\n# See the sudoers man page for the details on how to write a sudoers file. \r\n# \r\n \r\n# Host alias specification \r\n \r\n# User alias specification \r\n \r\n# Cmnd alias specification \r\n \r\n# Defaults specification \r\n \r\n# User privilege specification \r\nroot  ALL=(ALL) ALL \r\n \r\n# Uncomment to allow people in group wheel to run all commands \r\n# %wheel    ALL=(ALL)    ALL \r\n \r\n# Same thing without a password \r\n# %wheel    ALL=(ALL)    NOPASSWD: ALL \r\n \r\n# Samples \r\n# %users ALL=\/sbin\/mount \/cdrom,\/sbin\/umount \/cdrom \r\n# %users localhost=\/sbin\/shutdown -h now \r\n################################################################## <\/pre>\n

    1. \u6700\u7b80\u5355\u7684\u914d\u7f6e\uff0c\u8ba9\u666e\u901a\u7528\u6237support\u5177\u6709root\u7684\u6240\u6709\u6743\u9650
    \n\u6267\u884cvisudo\u4e4b\u540e\uff0c\u53ef\u4ee5\u770b\u89c1\u7f3a\u7701\u53ea\u6709\u4e00\u6761\u914d\u7f6e\uff1a<\/p>\n

    root    ALL=(ALL) ALL <\/pre>\n

    \u90a3\u4e48\u4f60\u5c31\u5728\u4e0b\u8fb9\u518d\u52a0\u4e00\u6761\u914d\u7f6e\uff1a<\/p>\n

    support ALL=(ALL) ALL<\/pre>\n

    \u8fd9\u6837\uff0c\u666e\u901a\u7528\u6237support\u5c31\u80fd\u591f\u6267\u884croot\u6743\u9650\u7684\u6240\u6709\u547d\u4ee4<\/p>\n

    \u4ee5support\u7528\u6237\u767b\u5f55\u4e4b\u540e\uff0c\u6267\u884c\uff1a <\/p>\n

    sudo su - <\/pre>\n

    \u7136\u540e\u8f93\u5165support\u7528\u6237\u81ea\u5df1\u7684\u5bc6\u7801\uff0c\u5c31\u53ef\u4ee5\u5207\u6362\u6210root\u7528\u6237\u4e86<\/p>\n

    2. \u8ba9\u666e\u901a\u7528\u6237support\u53ea\u80fd\u5728\u67d0\u51e0\u53f0\u670d\u52a1\u5668\u4e0a\uff0c\u6267\u884croot\u80fd\u6267\u884c\u7684\u67d0\u4e9b\u547d\u4ee4
    \n\u9996\u5148\u9700\u8981\u914d\u7f6e\u4e00\u4e9bAlias\uff0c\u8fd9\u6837\u5728\u4e0b\u9762\u914d\u7f6e\u6743\u9650\u65f6\uff0c\u4f1a\u65b9\u4fbf\u4e00\u4e9b\uff0c\u4e0d\u7528\u5199\u5927\u6bb5\u5927\u6bb5\u7684\u914d\u7f6e\u3002Alias\u4e3b\u8981\u5206\u62104\u79cd<\/p>\n

    Host_Alias \r\nCmnd_Alias \r\nUser_Alias \r\nRunas_Alias <\/pre>\n

    1) \u914d\u7f6eHost_Alias\uff1a\u5c31\u662f\u4e3b\u673a\u7684\u5217\u8868<\/p>\n

    Host_Alias      HOST_FLAG = hostname1, hostname2, hostname3 <\/pre>\n

    2) \u914d\u7f6eCmnd_Alias\uff1a\u5c31\u662f\u5141\u8bb8\u6267\u884c\u7684\u547d\u4ee4\u7684\u5217\u8868 <\/p>\n

    Cmnd_Alias      COMMAND_FLAG = command1, command2, command3 <\/pre>\n

    3) \u914d\u7f6eUser_Alias\uff1a\u5c31\u662f\u5177\u6709sudo\u6743\u9650\u7684\u7528\u6237\u7684\u5217\u8868 <\/p>\n

    User_Alias USER_FLAG = user1, user2, user3 <\/pre>\n

    4) \u914d\u7f6eRunas_Alias\uff1a\u5c31\u662f\u7528\u6237\u4ee5\u4ec0\u4e48\u8eab\u4efd\u6267\u884c\uff08\u4f8b\u5982root\uff0c\u6216\u8005oracle\uff09\u7684\u5217\u8868 <\/p>\n

    Runas_Alias RUNAS_FLAG = operator1, operator2, operator3 <\/pre>\n

    5) \u914d\u7f6e\u6743\u9650 <\/p>\n

    \u914d\u7f6e\u6743\u9650\u7684\u683c\u5f0f\u5982\u4e0b\uff1a <\/p>\n

    USER_FLAG HOST_FLAG=(RUNAS_FLAG) COMMAND_FLAG <\/pre>\n

    \u5982\u679c\u4e0d\u9700\u8981\u5bc6\u7801\u9a8c\u8bc1\u7684\u8bdd\uff0c\u5219\u6309\u7167\u8fd9\u6837\u7684\u683c\u5f0f\u6765\u914d\u7f6e <\/p>\n

    USER_FLAG HOST_FLAG=(RUNAS_FLAG) NOPASSWD: COMMAND_FLAG<\/p>\n

    \u914d\u7f6e\u793a\u4f8b\uff1a<\/p>\n

    ############################################################################\r\n# sudoers file. \r\n# \r\n# This file MUST be edited with the 'visudo' command as root. \r\n# \r\n# See the sudoers man page for the details on how to write a sudoers file. \r\n# \r\n \r\n# Host alias specification \r\nHost_Alias   EPG = 192.168.1.1, 192.168.1.2 \r\n \r\n# User alias specification \r\n \r\n# Cmnd alias specification \r\nCmnd_Alias   SQUID = \/opt\/vtbin\/squid_refresh, \/sbin\/service, \/bin\/rm\r\n \r\n# Defaults specification \r\n \r\n# User privilege specification \r\nroot  ALL=(ALL) ALL \r\nsupport EPG=(ALL) NOPASSWD: SQUID \r\n \r\n# Uncomment to allow people in group wheel to run all commands \r\n# %wheel    ALL=(ALL)    ALL \r\n \r\n# Same thing without a password \r\n# %wheel    ALL=(ALL)    NOPASSWD: ALL \r\n \r\n# Samples \r\n# %users ALL=\/sbin\/mount \/cdrom,\/sbin\/umount \/cdrom \r\n# %users localhost=\/sbin\/shutdown -h now \r\n##################################################<\/pre>\n","protected":false},"excerpt":{"rendered":"

    sudo\u662flinux\u4e0b\u5e38\u7528\u7684\u5141\u8bb8\u666e\u901a\u7528\u6237\u4f7f\u7528\u8d85\u7ea7\u7528\u6237\u6743\u9650\u7684\u5de5\u5177\uff0c\u5141\u8bb8\u7cfb\u7edf\u7ba1\u7406\u5458\u8ba9\u666e\u901a\u7528\u6237\u6267\u884c\u4e00\u4e9b\u6216\u8005\u5168\u90e8\u7684ro […]<\/p>\n","protected":false},"author":310,"featured_media":204689,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-204691","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\/204691","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=204691"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/204691\/revisions"}],"predecessor-version":[{"id":204750,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/204691\/revisions\/204750"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/204689"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=204691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=204691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=204691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}