{"id":262,"date":"2014-06-29T12:00:07","date_gmt":"2014-06-29T12:00:07","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=262"},"modified":"2014-06-29T12:00:07","modified_gmt":"2014-06-29T12:00:07","slug":"linux%e4%b8%8b%e7%9a%84etcsudoers%e6%96%87%e4%bb%b6%e7%9a%84%e4%b8%80%e4%ba%9b%e8%af%b4%e6%98%8e","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/262.html","title":{"rendered":"Linux\u4e0b\u7684\/etc\/sudoers\u6587\u4ef6\u7684\u4e00\u4e9b\u8bf4\u660e"},"content":{"rendered":"<h4><span style=\"color: #ff0000;\">Linux\u4e0b\u7684\/etc\/sudoers\u6587\u4ef6\u7684\u4e00\u4e9b\u8bf4\u660e<\/span><\/h4>\n<div>\u8fdb\u5165Ubuntu\u7cfb\u7edf\uff0c\u7528sudo\u547d\u4ee4\u7684\u65f6\u5019\u51fa\u73b0\u4e86\u4e0b\u9762\u7684\u9519\u8bef\u63d0\u793a\uff1a<br \/>\nsudo: \/etc\/sudoers is mode 0540, should be 0440<\/p>\n<p>\u89c9\u5f97\u96be\u4ee5\u7406\u89e3\uff0c\u600e\u4e48\u6211\u600e\u4e48\u4e0d\u80fd\u7528 sudo \u547d\u4ee4\u4e86\uff0c\u4e4b\u524d\u7528\u5f97\u597d\u597d\u7684\u5440\uff0c\u73b0\u5728\u600e\u4e48\u8fd9\u6837\u4e86\u3002<\/p>\n<p>\u53ea\u597d\u5148\u5207\u6362\u6210root\u7528\u6237\uff1a<br \/>\n$ su root<\/p>\n<p>\u66f4\u6539 \/etc\/sudoers \u6587\u4ef6\u7684\u5c5e\u6027\uff1a<br \/>\n# chmod 0440 \/etc\/sudoers<br \/>\n# chown root:root \/etc\/sudoers<\/p>\n<p>\u518d\u5207\u56de\u539f\u5148\u7684\u7528\u6237\uff0c\u53d1\u73b0\u53ef\u4ee5\u6b63\u5e38\u4f7f\u7528sudo\u4e86\u3002<\/p><\/div>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<div><a href=\"http:\/\/askubuntu.com\/questions\/50704\/sudo-error-is-mode-0777-should-be-0440\" target=\"_blank\">http:\/\/askubuntu.com\/questions\/50704\/sudo-error-is-mode-0777-should-be-0440<\/a><\/div>\n<div>\n<hr \/>\n<\/div>\n<div>sudo\u662flinux\u4e0b\u5e38\u7528\u7684\u5141\u8bb8\u666e\u901a\u7528\u6237\u4f7f\u7528\u8d85\u7ea7\u7528\u6237\u6743\u9650\u7684\u5de5\u5177\u3002<\/p>\n<p>\u5b83\u7684\u4e3b\u8981\u914d\u7f6e\u6587\u4ef6\u662f \/etc\/sudoers \uff0cLinux\u7cfb\u7edf\u901a\u5e38\u4f4d\u4e8e \/etc \u76ee\u5f55\u4e0b\uff0c\u5982\u679c\u662fsolaris\uff0c\u7f3a\u7701\u662f\u4e0d\u88c5 sudo\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 \u6587\u4ef6\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<p>\u8a00\u5f52\u6b63\u4f20\uff0c\u4e0b\u9762\u4ecb\u7ecd\u5982\u4f55\u914d\u7f6e \/etc\/sudoers \u6587\u4ef6\u3002<\/p>\n<p>\u9996\u5148\u5199sudoers\u7684\u7f3a\u7701\u914d\u7f6e\uff1a<\/p><\/div>\n<div>#########################################################<br \/>\n# sudoers file.<br \/>\n#<br \/>\n# This file MUST be edited with the \u2018visudo\u2019 command as root.<br \/>\n#<br \/>\n# See the sudoers man page for the details on how to write a sudoers file.<br \/>\n#<br \/>\n# Host alias specification<br \/>\n# User alias specification<br \/>\n# Cmnd alias specification<br \/>\n# Defaults specification<br \/>\n# User privilege specification<br \/>\n<span style=\"color: #ff0000; font-size: large;\"><strong>root ALL=(ALL) ALL<\/strong><\/span><br \/>\n# Uncomment to allow people in group wheel to run all commands<br \/>\n# %wheel ALL=(ALL) ALL<\/div>\n<p><strong><span style=\"color: #ff0000;\">\u7528\u6237\u540d<span style=\"color: #0000ff;\">\u4e3b\u673a<\/span> \u6743\u9650 \u547d\u4ee4\u5217\u8868\u00a0\u00a0\u00a0\u00a0#<\/span><span style=\"color: #0000ff;\">\u6743\u9650\u9ed8\u8ba4\u7701\u7565\uff0c\u4e0d\u7528\u6307\u5b9a<\/span><\/strong><br \/>\n# <span style=\"color: #ff0000;\"><strong>Same thing without a password<\/strong><\/span><br \/>\n# %wheel ALL=(ALL) NOPASSWD: ALL<br \/>\n# Samples<br \/>\n# %users ALL=\/sbin\/mount \/cdrom,\/sbin\/umount \/cdrom<br \/>\n# %users localhost=\/sbin\/shutdown -h now<br \/>\n#########################################################<\/p>\n<h5><strong>1. \u6700\u7b80\u5355\u7684\u914d\u7f6e\uff0c\u8ba9\u7528\u6237support\u5177\u6709root\u7684\u6240\u6709\u6743\u9650<\/strong><\/h5>\n<p>\u6267\u884cvisudo\u4e4b\u540e\uff0c\u53ef\u4ee5\u770b\u89c1\u7f3a\u7701\u53ea\u6709\u4e00\u6761\u914d\u7f6e\uff1a<br \/>\nroot ALL=(ALL) ALL<br \/>\n\u90a3\u4e48\u4f60\u5c31\u5728\u4e0b\u8fb9\u518d\u52a0\u4e00\u6761\u914d\u7f6e\uff1a<br \/>\nsupport ALL=(ALL) ALL<br \/>\n\u8fd9\u6837\uff0c\u666e\u901a\u7528\u6237support\u5c31\u80fd\u591f\u6267\u884croot\u6743\u9650\u7684\u6240\u6709\u547d\u4ee4<br \/>\n\u4ee5support\u7528\u6237\u767b\u5f55\u4e4b\u540e\uff0c\u6267\u884c\uff1a<br \/>\nsudo su &#8211;<br \/>\n\u7136\u540e\u8f93\u5165support\u7528\u6237\u81ea\u5df1\u7684\u5bc6\u7801\uff0c\u5c31\u53ef\u4ee5\u5207\u6362\u6210root\u7528\u6237\u4e86<\/p>\n<h5><span style=\"color: #ff0000; font-size: large;\"><strong>2. \u8ba9\u7528\u6237support\u53ea\u80fd\u5728\u67d0\u51e0\u53f0\u670d\u52a1\u5668\u4e0a\uff0c\u6267\u884croot\u80fd\u6267\u884c\u7684\u67d0\u4e9b\u547d\u4ee4<\/strong><\/span><\/h5>\n<div>\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\uff1a<\/div>\n<ol>\n<li>Host_Alias<\/li>\n<li>Cmnd_Alias<\/li>\n<li>User_Alias<\/li>\n<li>Runas_Alias<\/li>\n<\/ol>\n<h6>1) \u914d\u7f6eHost_Alias\uff1a\u5c31\u662f\u4e3b\u673a\u7684\u5217\u8868<\/h6>\n<div>Host_Alias HOST_FLAG = hostname1, hostname2, hostname3<\/div>\n<h6>2) \u914d\u7f6eCmnd_Alias\uff1a\u5c31\u662f\u5141\u8bb8\u6267\u884c\u7684\u547d\u4ee4\u7684\u5217\u8868<\/h6>\n<div>Cmnd_Alias COMMAND_FLAG = command1, command2, command3<\/div>\n<h6>3) \u914d\u7f6eUser_Alias\uff1a\u5c31\u662f\u5177\u6709sudo\u6743\u9650\u7684\u7528\u6237\u7684\u5217\u8868<\/h6>\n<div>User_Alias USER_FLAG = user1, user2, user3<\/div>\n<h6>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<\/h6>\n<div><\/div>\n<div>Runas_Alias RUNAS_FLAG = operator1, operator2, operator3<\/div>\n<h6>5) \u914d\u7f6e\u6743\u9650<\/h6>\n<div><\/div>\n<div>\u914d\u7f6e\u6743\u9650\u7684\u683c\u5f0f\u5982\u4e0b\uff1a<\/div>\n<div><\/div>\n<div>USER_FLAG HOST_FLAG=(RUNAS_FLAG) COMMAND_FLAG<\/div>\n<div>==<\/div>\n<div><\/div>\n<div>\u5982\u679c\u4e0d\u9700\u8981\u5bc6\u7801\u9a8c\u8bc1\u7684\u8bdd\uff0c\u5219\u6309\u7167\u8fd9\u6837\u7684\u683c\u5f0f\u6765\u914d\u7f6e<\/div>\n<div><\/div>\n<div>USER_FLAG HOST_FLAG=(RUNAS_FLAG) NOPASSWD: COMMAND_FLAG<\/div>\n<h6>\u914d\u7f6e\u793a\u4f8b\uff1a<\/h6>\n<div>#########################################################<br \/>\n# sudoers file.<br \/>\n#<br \/>\n# This file MUST be edited with the \u2018visudo\u2019 command as root.<br \/>\n#<br \/>\n# See the sudoers man page for the details on how to write a sudoers file.<br \/>\n#<br \/>\n# Host alias specification<br \/>\n<span style=\"color: #ff0000; font-size: large;\"><strong>Host_Alias EPG = 192.168.1.1, 192.168.1.2<\/strong><\/span><br \/>\n# User alias specification<br \/>\n# Cmnd alias specification<br \/>\n<span style=\"color: #ff0000;\"><strong>Cmnd_Alias SQUID = \/opt\/vtbin\/squid_refresh, \/sbin\/service, \/bin\/rm<\/strong><\/span><br \/>\n# Defaults specification<br \/>\n# User privilege specification<br \/>\nroot ALL=(ALL) ALL<br \/>\n<span style=\"color: #ff0000; font-size: medium;\"><strong>support EPG=(ALL) NOPASSWD: SQUID<\/strong><\/span><br \/>\n# Uncomment to allow people in group wheel to run all commands<br \/>\n# %wheel ALL=(ALL) ALL<br \/>\n# Same thing without a password<br \/>\n# %wheel ALL=(ALL) NOPASSWD: ALL<br \/>\n# Samples<br \/>\n# %users ALL=\/sbin\/mount \/cdrom,\/sbin\/umount \/cdrom<br \/>\n# %users localhost=\/sbin\/shutdown -h now<\/div>\n<div>===========================================<\/div>\n<div>\/etc\/sudoers | inotseeyou <a href=\"http:\/\/inotseeyou.com\/2011\/04\/02\/etcsudoers\/\" target=\"_blank\">http:\/\/inotseeyou.com\/2011\/04\/02\/etcsudoers\/<\/a><\/div>\n<div>===========================================<\/div>\n<div><span style=\"color: #4c4c4c;\">\u4f8b\u5b50\uff1a<\/span><\/div>\n<div><span style=\"color: #4c4c4c;\">jorge ALL=(root) \/usr\/bin\/find, \/bin\/rm<\/span><\/div>\n<div><\/div>\n<div><span style=\"color: #4c4c4c;\">\u3000\u3000\u4e0a\u9762\u7684\u7b2c\u4e00\u680f\u89c4\u5b9a\u5b83\u7684<span style=\"color: #ff0000; font-size: large;\"><strong>\u9002\u7528\u5bf9\u8c61<\/strong><\/span>\uff1a\u7528\u6237\u6216\u7ec4\uff0c\u5c31\u672c\u4f8b\u6765\u8bf4\uff0c\u5b83\u662f\u7528\u6237jorge\u3002\u6b64\u5916\uff0c\u56e0\u4e3a\u7cfb\u7edf\u4e2d\u7684\u7ec4\u548c\u7528\u6237\u53ef\u4ee5\u91cd\u540d\uff0c\u8981\u60f3\u6307\u5b9a\u8be5\u89c4\u5219\u7684\u9002\u7528\u5bf9\u8c61\u662f\u7ec4\u800c\u975e\u7528\u6237\u7684\u8bdd\uff0c\u7ec4\u5bf9\u8c61\u7684\u540d\u79f0\u4e00\u5b9a\u8981\u7528\u767e\u5206\u53f7%\u5f00\u5934\u3002<\/span><\/div>\n<div><\/div>\n<div><span style=\"color: #4c4c4c;\">\u3000\u3000\u7b2c\u4e8c\u680f\u6307\u5b9a\u8be5\u89c4\u5219\u7684<span style=\"color: #ff0000; font-size: large;\"><strong>\u9002\u7528\u4e3b\u673a<\/strong><\/span>\u3002\u5f53\u6211\u4eec\u5728\u591a\u4e2a\u7cfb\u7edf\u4e4b\u95f4\u90e8\u7f72sudo\u73af\u5883\u65f6\uff0c\u8fd9\u4e00\u680f\u683c\u5916\u6709\u7528\uff0c\u8fd9\u91cc\u7684ALL\u4ee3\u8868\u6240\u6709\u4e3b\u673a\u3002\u4f46\u662f\uff0c\u5bf9\u4e8e\u684c\u9762\u7cfb\u7edf\u6216\u4e0d\u60f3\u5c06sudo\u90e8\u7f72\u5230\u591a\u4e2a\u7cfb\u7edf\u7684\u60c5\u51b5\uff0c\u8fd9\u4e00\u680f\u5c31\u6362\u6210\u76f8\u5e94\u7684\u4e3b\u673a\u540d\u3002<\/span><\/div>\n<div><\/div>\n<div><span style=\"color: #4c4c4c;\">\u3000\u3000\u7b2c\u4e09\u680f\u7684\u503c\u653e\u5728\u62ec\u53f7\u5185\uff0c<span style=\"color: #ff0000; font-size: large;\"><strong>\u6307\u51fa\u7b2c\u4e00\u680f\u89c4\u5b9a\u7684\u7528\u6237\u80fd\u591f\u4ee5\u4f55\u79cd\u8eab\u4efd\u6765\u6267\u884c\u547d\u4ee4<\/strong><\/span>\u3002\u672c\u4f8b\u4e2d\u8be5\u503c\u8bbe\u4e3aroot\uff0c\u8fd9\u610f\u5473\u7740\u7528\u6237jorge\u80fd\u591f\u4ee5root\u7528\u6237\u7684\u8eab\u4efd\u6765\u8fd0\u884c\u540e\u9762\u5217\u51fa\u7684\u547d\u4ee4\u3002<span style=\"color: #ff0000;\">\u8be5\u503c\u4e5f\u53ef\u4ee5\u8bbe\u6210\u901a\u914d\u7b26ALL\uff0cjorge\u4fbf\u80fd\u4f5c\u4e3a\u7cfb\u7edf\u4e2d\u7684\u4efb\u4f55\u7528\u6237\u6765\u6267\u884c\u5217\u51fa\u7684\u547d\u4ee4\u4e86\u3002<\/span><\/span><\/div>\n<div><\/div>\n<div><span style=\"color: #4c4c4c;\"><span style=\"color: #4c4c4c;\">\u3000\u3000\u6700\u540e\u4e00\u680f\uff08\u5373\/usr\/bin\/find,\/bin\/rm\uff09\u662f<span style=\"color: #ff0000; font-size: large;\"><strong>\u4f7f\u7528\u9017\u53f7\u5206\u5f00\u7684\u547d\u4ee4\u8868<\/strong><\/span>\uff0c\u8fd9\u4e9b\u547d\u4ee4\u80fd\u88ab\u7b2c\u4e00\u680f\u89c4\u5b9a\u7684\u7528\u6237\u4ee5\u7b2c\u4e09\u680f\u6307\u51fa\u7684\u8eab\u4efd\u6765\u8fd0\u884c\u5b83\u4eec\u3002\u672c\u4f8b\u4e2d\uff0c\u8be5\u914d\u7f6e\u5141\u8bb8jorge\u4f5c\u4e3a\u8d85\u7ea7\u7528\u6237\u8fd0\u884c\/usr\/bin\/find\u548c \/bin\/rm\u8fd9\u4e24\u4e2a\u547d\u4ee4\u3002\u9700\u8981\u6307\u51fa\u7684\u662f\uff0c\u8fd9\u91cc\u5217\u51fa\u7684\u547d\u4ee4\u4e00\u5b9a\u8981\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84\u3002<\/span><\/span><\/div>\n<div>\n<hr \/>\n<\/div>\n<div>\u5bf9 Linux \u6709\u4e00\u5b9a\u4e86\u89e3\u7684\u4eba\u591a\u5c11\u4e5f\u4f1a\u77e5\u9053\u70b9\u5173\u4e8esudo\u547d\u4ee4\u3002<\/p>\n<p>sudo\u547d\u4ee4\u7684\u6838\u5fc3\u601d\u60f3\u662f\u6743\u9650\u7684\u8d4b\u4e88\uff0c\u5373\u67d0\u4e2a\u547d\u4ee4\u7684\u6240\u5c5e\u7528\u6237\u4e0d\u662f\u4f60\u81ea\u5df1\uff0c\u800c\u4f60\u5374\u6709\u6743\u9650\u6267\u884c\u5b83\u3002\u4f46\u662f\u6211\u4eec\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u867d\u7136\u4f60\u6709\u6743\u9650\u6267\u884c\u8fd9\u4e2a\u547d\u4ee4\uff0c\u4f46\u662f\u5728\u6267\u884c\u7684\u65f6\u5019\u5374\u4ecd\u662f\u4ee5\u8fd9\u4e2a\u547d\u4ee4\u672c\u8eab\u6240\u5c5e\u7528\u6237\u6765\u5b8c\u6210\u7684[\u6ce8\u91ca]\u3002(su\u547d\u4ee4\u7c7b\u4f3csudo\u547d\u4ee4\uff0c\u4f46\u662f\u4e24\u8005\u7684\u5dee\u522b\u5728\u4e8e\u524d\u8005su\u662f\u4e00\u4e2a\u7c97\u7c92\u5ea6\u6743\u9650\u8d4b\u4e88\uff0c<\/p>\n<p>\u5bf9su\u6700\u597d\u7684\u7406\u89e3\u6211\u89c9\u5f97\u662f change user running command permanent \u3002\u5373\u6c38\u4e45\u7684\u5207\u6362\u5230\u4e86su\u8fc7\u53bb\u7684\u7528\u6237\uff0c\u7136\u540e\u4ee5\u8fd9\u4e2asu\u5230\u7684\u65b0\u7528\u6237\u5e72\u5b83\u80fd\u5e72\u7684\u4e00\u5207\u4e8b\u60c5\uff0c\u800c sudo \u5219\u662f\u6307\u5728\u6267\u884c\u67d0\u4e2a\u547d\u4ee4\u7684\u65f6\u5019\u4e34\u65f6\u5207\u6362\u5230\u8fd9\u4e2a\u547d\u4ee4\u7684\u6240\u5c5e\u7528\u6237\u6267\u884c[\u6ce8\u91ca]\uff0c\u800c\u4e14sudo\u53ef\u4ee5\u505a\u5230\u4ee5\u5355\u4e2a\u547d\u4ee4\u4e3a\u5355\u4f4d\u5c06\u6743\u9650\u8d4b\u4e88\u7ed9\u5176\u4ed6\u7528\u6237\uff0c\u76f8\u6bd4 su \u663e\u5f97\u66f4\u52a0\u7075\u6d3b\u3002)<\/p>\n<p>\u5927\u6982\u4e86\u89e3\u4e86sudo\u7684\u529f\u80fd\uff0c\u90a3\u4e48\u4f60\u77e5\u9053\u600e\u4e48\u914d\u7f6e sudo \u5417\uff1f\u4e0b\u9762\u6765\u7b80\u8981\u8bf4\u660e\u4e00\u4e0b\uff1a<\/p>\n<p>\u914d\u7f6esudo\u7684\u914d\u7f6e\u6587\u4ef6\u5728\/etc\/sudoers\u91cc\u9762\uff0c\u4e00\u822c\u901a\u8fc7visudo\u547d\u4ee4\u6765\u5b89\u5168\u6253\u5f00\u7f16\u8f91\u3002\u67e5\u770b\/etc\/sudoers\u7684\u7528\u6cd5\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4: man 5 sudoers\u3002\u5728\/etc\/sudoers\u6587\u4ef6\u91cc\u9762\u4e3b\u8981\u5305\u62ec\u8fd9\u4e24\u90e8\u5206\uff1a<\/p><\/div>\n<h6><strong style=\"color: #000000;\">1. \u522b\u540d\u8bbe\u7f6e<\/strong><\/h6>\n<div><span style=\"color: #000000;\">\u522b\u540d\u4e3b\u8981\u5305\u62ec\u8fd9\u51e0\u79cd\uff1aUser_Alias,Host_Alias,Runas_Alias,Cmnd_Alias\uff0c\u5206\u522b\u662f\u7528\u6237\u522b\u540d\uff0c\u4e3b\u673a\u522b\u540d\uff0c\u8fd0\u884c\u7528\u6237\u522b\u540d\uff0c\u547d\u4ee4\u522b\u540d\u3002\u8bbe\u7f6e\u8fd9\u51e0\u4e2a\u522b\u540d\u7684\u547d\u4ee4\u4e3b\u8981\u662f\u4e3a\u4e86\u914d<\/span><span style=\"color: #000000;\">\u7f6e\u65b9\u4fbf\uff0c\u8fd9\u4e2a\u5f88\u7c7b\u4f3cLinux\u7528\u6237\u7fa4\u7ec4\u6216\u662f\u6570\u636e\u5e93\u4e2d\u89d2\u8272\u7684\u4f5c\u7528\uff0c\u6709\u4e86\u522b\u540d\u4fbf\u53ef\u4ee5\u6279\u91cf\u7684\u8d4b\u4e88\u6743\u9650\u3002<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u8bbe\u7f6e\u65b9\u6cd5\uff1a<\/span><\/div>\n<div><span style=\"color: #000000;\">Alias_Type alias_name = name1, name2, name3<\/span><\/div>\n<div><span style=\"color: #000000;\">\u4f8b\u5982\uff1a<\/span><\/div>\n<div><span style=\"color: #000000;\">User_Alias User1 = user1, user2, user3<\/span><\/div>\n<div><span style=\"color: #000000;\">\u5176\u4ed6\u7c7b\u578b\u7684alias\u8bbe\u7f6e\u65b9\u6cd5\u7c7b\u4f3c\u3002<\/span><\/div>\n<h6><strong style=\"color: #000000;\">2. \u771f\u6b63\u7684sudo entry<\/strong><\/h6>\n<div>\u8fd9\u4e2a\u5c31\u662f\u771f\u6b63\u914d\u7f6e\u54ea\u4e9b\u7528\u6237\u53ef\u4ee5\u4f7f\u7528\u54ea\u4e9b\u547d\u4ee4\u4e86\uff08\u4f60\u751a\u81f3\u53ef\u4ee5\u4e0d\u4f7f\u7528\u522b\u540d\u8bbe\u7f6e\u90a3\u90e8\u5206\uff09\u3002<br \/>\n<strong><span style=\"color: #ff0000;\">\u683c\u5f0f\u4e3a<\/span><\/strong>\uff1a\u7528\u6237\u540d(\u7528\u6237\u522b\u540d) \u4e3b\u673a\u540d(\u4e3b\u673a\u522b\u540d)=[(\u8fd0\u884c\u7528\u6237\u6216\u662fRunas_Alias)\u53ef\u9009] [tag\u53ef\u9009] \u00a0\u53ef\u4ee5\u6267\u884c\u7684\u547d\u4ee4(\u6216Cmmd_Alias)<\/div>\n<div><\/div>\n<div>\u8fd9\u6837\u63cf\u8ff0\u8bed\u6cd5\u5f88\u751f\u786c\uff0c\u4e0d\u6613\u7406\u89e3\uff0c\u4e3e\u4f8b\u5b50\uff1a<\/div>\n<div>\n<pre class=\"lang:default decode:true\">user1 \u00a0host1 = \/bin\/kill\u00a0\u00a0# user1 \u53ef\u4ee5\u5728host1\u4e0a\u4f7f\u7528\u547d\u4ee4\/bin\/kill\nuser1 \u00a0host1 = NOPASSWD: \/bin\/kill\u00a0\u00a0# user1 \u53ef\u4ee5\u5728host1\u4e0a\u4f7f\u7528\u547d\u4ee4\/bin\/kill \u540c\u65f6\u53ef\u4ee5\u4e0d\u5fc5\u8f93\u5165\u5bc6\u7801(\u8fd9\u91cc\u5c31\u662f\u4f7f\u7528\u4e86NOPASSWD\uff0c\u8fd9\u4e2atag\uff0c\u9ed8\u8ba4\u662fPASSWD)\nuser1 \u00a0host1 = NOPASSWD: \/bin\/kill , PASSWORD: \/bin\/ls\u00a0\u00a0# user1 \u53ef\u4ee5\u5728host1\u4e0a\u4f7f\u7528\u547d\u4ee4\/bin\/kill\u65e0\u9700\u8f93\u5165\u5bc6\u7801\uff0c\u4f46\u662f\u4f7f\u7528\/bin\/ls\u5219\u9700\u8981\u8f93\u5165\u5bc6\u7801\nuser1 \u00a0host1 = (opterator) \/bin\/kill\u00a0\u00a0# user1 \u53ef\u4ee5\u5728host1\u4e0a\u4f7f\u7528\u547d\u4ee4\/bin\/kill\u4f46\u662f\u5fc5\u987b\u662f\u4ee5operator\u7528\u6237\u8fd0\u884c\u8fd9\u4e2a\u547d\u4ee4\uff0c\u7b49\u4ef7\u4e8e su -u opertor \/bin\/kill\nuser1 \u00a0host1 = (:group_name) \/bin\/kill\u00a0\u00a0# user1 \u53ef\u4ee5\u5728host1\u4e0a\u4f7f\u7528\u547d\u4ee4\/bin\/kill,\u4e14\u5fc5\u987b\u4ee5group_name\u8fd9\u4e2a\u7528\u6237\u7fa4\u7ec4\u91cc\u9762\u7684\u7528\u6237\u6765\u8fd0\u884c\u3002\n%group_name host1 = \/bin\/kill\u00a0\u00a0# \u6240\u6709group_name\u91cc\u9762\u7684\u7528\u6237\u90fd\u53ef\u4ee5\u5728host1\u4e0a\u6267\u884c\/bin\/kill(linux\u4e2d\u4e00\u822c\u4ee3\u8868\u6574\u4e2a\u7528\u6237\u7fa4\u7ec4\u7528%group_name)<\/pre>\n<p>\u518d\u4e3e\u4e2a\u5b9e\u9645\u4f8b\u5b50\uff0c\u6211\u4e4b\u524d\u5bf9 sudo su \u8fd9\u4e2a\u547d\u4ee4\u4e0d\u7406\u89e3\uff0c\u4e3a\u4ec0\u4e48\u6211\u53ef\u4ee5\u76f4\u63a5\u5c31 su \u5230 root \u7528\u6237\u4e86\u5462\uff0c\u8fde\u5bc6\u7801\u90fd\u4e0d\u9700\u8981\uff1f\u67e5\u770b\u4e86\u4e00\u4e0b \/etc\/sudoers \u6587\u4ef6\u624d\u77e5\u9053\u539f\u6765\u91cc\u9762\u6709\u8fd9\u4e48\u4e00\u884c\uff1a<\/p>\n<pre class=\"lang:default decode:true\">xxx ALL=NOPASSWD: \/bin\/su<\/pre>\n<p>\u6ce8\u91ca\uff1a<br \/>\n\u5728Linux\u4e2d\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u662f\u6709\u4e0e\u4e4b\u76f8\u5173\u7684UID\/GID\uff0c\u5206\u4e3a\u6709\u6548UID\uff0c\u771f\u5b9eUID\uff0c\u6709\u6548GID\uff0c\u771f\u5b9eGID\u3002\u6709\u6548UID\uff0cGID\u662f\u7528\u6765\u5224\u65ad\u6743\u9650\uff0c\u800c\u771f\u5b9eUID\uff0cGID\u662f\u7528\u6765\u8bb0\u8d26(\u54ea\u4e2a\u8fdb\u7a0b\u5c5e\u4e8e\u54ea\u4e2a\u7528\u6237\uff0c\u6216\u8bb0\u5f55\u65e5\u5fd7\u7b49\u7b49)\u3002\u5f53\u914d\u7f6e\u4e86sudo entry\u540e\uff0c\u6709\u6548UID\u91cc\u9762\u5c31\u5305\u542b\u4e86\u8fd9\u4e2a\u88ab\u914d\u7f6e\u7684\u7528\u6237UID\uff0c\u56e0\u800c\u6743\u9650\u9a8c\u8bc1\u7684\u65f6\u5019\u5c31\u53ef\u4ee5\u901a\u8fc7\u3002<\/p><\/div>\n<h6><strong style=\"color: #000000;\">\u53c2\u8003\u6587\u7ae0\uff1a<\/strong><\/h6>\n<ul>\n<li><span style=\"color: #000000;\">Linux\u6280\u672f\u7ba1\u7406\u624b\u518c<\/span><\/li>\n<li><span style=\"color: #000000;\">Unix\u9ad8\u7ea7\u73af\u5883\u7f16\u7a0b<\/span><\/li>\n<li><span style=\"color: #000000;\">man sudoers<\/span><\/li>\n<\/ul>\n<h6>Tips\u5c0f\u7ed3<\/h6>\n<div>\n<pre class=\"lang:default decode:true\">:w !sudo tee %\u00a0\u00a0\u00a0 #\u5728Vim\u4e2d\u4fdd\u5b58\u5bf9\u53ea\u8bfb\u6587\u4ef6\u4f5c\u51fa\u7684\u4fee\u6539<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Linux\u4e0b\u7684\/etc\/sudoers\u6587\u4ef6\u7684\u4e00\u4e9b\u8bf4\u660e \u8fdb\u5165Ubuntu\u7cfb\u7edf\uff0c\u7528sudo\u547d\u4ee4\u7684\u65f6\u5019\u51fa\u73b0\u4e86\u4e0b\u9762\u7684\u9519 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,6,25],"tags":[30,126,127],"class_list":["post-262","post","type-post","status-publish","format-standard","hentry","category-linux","category-other","category-security","tag-linux","tag-sudo","tag-sudoers"],"views":5595,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=262"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/262\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}