{"id":281853,"date":"2023-09-02T20:05:51","date_gmt":"2023-09-02T12:05:51","guid":{"rendered":"https:\/\/lrxjmw.cn\/lxtglysysdml.html"},"modified":"2023-09-02T20:05:51","modified_gmt":"2023-09-02T12:05:51","slug":"lxtglysysdml","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/lxtglysysdml.html","title":{"rendered":"Linux\u7cfb\u7edf\u7ba1\u7406\u5458\u4f7f\u7528sudo\u7684\u547d\u4ee4\u4fee\u6539"},"content":{"rendered":"
sudo\u662flinux\u4e0b\u5e38\u7528\u7684\u5bb9\u8bb8\u666e\u901a\u7528\u6237\u4f7f\u7528\u8d85\u7ea7\u7528\u6237\u6743\u9650\u7684\u5de5\u5177\uff0c\u5bb9\u8bb8\u7cfb\u7edf<\/a>\u7ba1\u7406\u5458\u8ba9\u666e\u901a\u7528\u6237\u6267\u884c\u4e00\u4e9b\u6216\u5219\u5168\u90e8\u7684root\u547d\u4ee4<\/a>\uff0c\u5982halt\uff0creboot\uff0csu\u7b49\u7b49\u3002\u8fd9\u6837\u9664\u4e86\u964d\u4f4e\u4e86root\u7528\u6237\u7684\u7ba1\u7406\u65f6\u95f4linux\u67e5\u770b\u6587\u4ef6\u6743\u9650<\/strong>\uff0c\u540c\u6837\u4e5f\u589e\u5f3a\u4e86\u5b89\u5168\u6027\u3002Sudo\u4e0d\u662f\u5bf9shell\u7684\u4e00\u4e2a\u66ff\u4ee3\uff0c\u5b83\u662f\u9762\u5411\u6bcf\u4f4d\u547d\u4ee4\u7684\u3002<\/p>\n sudo\u7684\u914d\u7f6e\u6587\u4ef6\u662f\/etc\/sudoers\u6587\u4ef6linux\u8bbe\u7f6e\u9ed8\u8ba4\u7f51\u5173\uff0c\u5b83\u5bb9\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<\/p>\n sudo\u90fd\u63d0\u4f9b\u4e86\u4e00\u4e2a\u7f16\u8f91\u8be5\u6587\u4ef6\u7684\u547d\u4ee4\uff1avisudo\u6765\u5bf9\u8be5\u6587\u4ef6\u8fdb\u884c\u66f4\u6539\u3002\u5f3a\u70c8\u63a8\u8350\u4f7f\u7528\u8be5\u547d\u4ee4\u66f4\u6539sudoers\uff0c\u7531\u4e8e\u5b83\u4f1a\u5e2e\u4f60\u6821\u51c6\u6587\u4ef6\u914d\u7f6e\u662f\u5426\u6b63\u786e\uff0c\u5047\u82e5\u4e0d\u6b63\u786eredhat linux\uff0c\u5728\u4fdd\u5b58\u9000\u51fa\u65f6\u90fd\u4f1a\u63d0\u793a\u4f60\u54ea\u6bb5\u914d\u7f6e\u51fa\u9519\u7684\u3002<\/p>\n \u6253\u5f00\/etc\/sudoers\u6587\u4ef6\u53ef\u4ee5\u53d1\u89c9\u4e00\u4e2a\u7279\u6b8a\u7684wheel\u7ec4<\/p>\n \n \u7b2c2\u884c\u8868\u793a\uff1awheel\u7ec4\u4e2d\u7684\u7528\u6237\u53ef\u4ee5\u5728ALL\/\u4efb\u610f\u4e3b\u673a\u4e0a\u4ee5\u4efb\u610f\u7528\u6237\u6267\u884c\u6240\u6709\u7684\u547d\u4ee4\uff0c\u4e0d\u8fc7\u987b\u8981\u8f93\u5165\u8be5\u7528\u6237\u81ea\u5df1\u7684\u5bc6\u7801\u3002<\/p>\n \u7b2c4\u884c\u5728\u7b2c2\u884c\u7684\u57fa\u7840\u4e0a\u964d\u4f4e\u4e86NOPASSWD\uff0c\u610f\u601d\u662f\u65e0\u9700\u8f93\u5165\u5bc6\u7801\u3002\u4e0d\u8fc7\u8fd9\u884c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u662f\u6ce8\u91ca\u6389\u7684\u3002<\/p>\n \u8fd9\u6837\u6211\u4eec\u53ea\u987b\u8981\u521b\u5efa\u4e00\u4e2a\u4e13\u7528\u7684\u5e10\u6237linux\u67e5\u770b\u6587\u4ef6\u6743\u9650<\/strong>\uff0c\u4e4b\u540e\u5c06\u5176\u6dfb\u52a0\u5230wheel\u7ec4\u3002<\/p>\n \u6dfb\u52a0\u7528\u6237<\/p>\n \u521b\u5efa\u7528\u6237jupiter<\/p>\n \n \u6388\u4e88sudo\u6743\u9650<\/p>\n \u5c06\u7528\u6237\u6dfb\u52a0\u5230wheel\u7ec4\u4e2d<\/p>\n \n \u5982\u4eca\u7528\u6237jupiter\u5c31\u53ef\u4ee5\u6267\u884c\u4e00\u4e9b\u672c\u6765root\u7528\u6237\u80fd\u591f\u6267\u884c\u7684\u547d\u4ee4\u3002<\/p>\n \u6d4b\u8bd5<\/p>\n \u9996\u5148\u5207\u6362\u5230jupiter\u7528\u6237<\/p>\n \n \u5c1d\u8bd5\u5207\u6362\u5230root\u7528\u623f\u4e3b\u76ee\u5f55\u88ab\u62d2\u7edd<\/p>\n \n \u6b64\u6b21\u4f7f\u7528sudo<\/p>\n \n \u4e4b\u540e\u5c31\u53ef\u4ee5\u6210\u529f\u5207\u6362\u5230root\u7528\u623f\u4e3b\u76ee\u5f55\u4e86\u3002<\/p>\n \u5018\u82e5\u4e0d\u60f3\u8f93\u5165\u5bc6\u7801\uff0c\u8fd9\u4e48\u53ef\u4ee5\u5c06\u524d\u9762\u63d0\u53ca\u7684\u7b2c4\u884c\u7684\u6ce8\u91ca\u5b57\u7b26#\u53bb\u9664\u3002<\/p>\n \u53c2\u8003<\/p>\n## Allows people in group wheel to run all commands\n%wheel ALL=(ALL) ALL\n## Same thing without a password\n# %wheel ALL=(ALL) NOPASSWD: ALL<\/code><\/pre>\n<\/p>\n
# adduser jupiter\n# passwd jupiter\n# cat \/etc\/passwd | grep jupiter\njupiter:x:1000:1000::\/home\/jupiter:\/bin\/bash<\/code><\/pre>\n<\/p>\n
# gpasswd -a jupiter wheel\nAdding user jupiter to group wheel<\/code><\/pre>\n<\/p>\n
# su jupiter<\/code><\/pre>\n<\/p>\n
$ cd \/root\nbash: cd: \/root: Permission denied\n<\/code><\/pre>\n<\/p>\n
$ sudo cd \/root\nWe trust you have received the usual lecture from the local System\nAdministrator. It usually boils down to these three things:\n #1) Respect the privacy of others.\n #2) Think before you type.\n #3) With great power comes great responsibility.\n[sudo] password for jupiter: \u8fd9\u91cc\u8f93\u5165jupiter\u7684\u5bc6\u7801<\/code><\/pre>\n<\/p>\n