{"id":134470,"date":"2019-01-23T16:44:03","date_gmt":"2019-01-23T08:44:03","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=134470"},"modified":"2019-01-23T13:06:30","modified_gmt":"2019-01-23T05:06:30","slug":"useradd-command-usage","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/useradd-command-usage.html","title":{"rendered":"useradd \u547d\u4ee4\u7684\u5e38\u89c1\u7528\u6cd5"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728 Linux \u4e2d useradd \u662f\u4e2a\u5f88\u57fa\u672c\u7684\u547d\u4ee4\uff0c\u4f46\u662f\u4f7f\u7528\u8d77\u6765\u5374\u5f88\u4e0d\u76f4\u89c2\u3002\u4ee5\u81f3\u4e8e\u5728 Ubuntu \u4e2d\u5c45\u7136\u6dfb\u52a0\u4e86\u4e00\u4e2a adduser \u547d\u4ee4\u6765\u7b80\u5316\u6dfb\u52a0\u7528\u6237\u7684\u64cd\u4f5c\u3002\u672c\u6587\u4e3b\u8981\u63cf\u8ff0\u7b14\u8005\u5728\u5b66\u4e60\u4f7f\u7528 useradd \u547d\u4ee4\u65f6\u7684\u4e00\u4e9b\u6d4b\u8bd5\u7ed3\u679c\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u8bf4\u660e\uff1a\u672c\u6587\u4e2d\u7684\u6240\u6709\u8bd5\u9a8c\u90fd\u662f\u5728 Ubuntu14.04 \u4e0a\u5b8c\u6210\u3002<\/p>\n

\u529f\u80fd<\/strong><\/div>\n

\u5728Linux\u4e2d useradd \u547d\u4ee4\u7528\u6765\u521b\u5efa\u6216\u66f4\u65b0\u7528\u6237\u4fe1\u606f\u3002<\/p>\n

useradd \u547d\u4ee4\u5c5e\u4e8e\u6bd4\u8f83\u96be\u7528\u7684\u547d\u4ee4 (low level utility for adding users)\uff0c\u6240\u4ee5 Debian \u7cfb\u7684\u53d1\u884c\u7248\u4e2d\u5efa\u8bae\u7ba1\u7406\u5458\u4f7f\u7528 adduser \u547d\u4ee4\u3002\u5176\u5b9e adduser \u547d\u4ee4\u53ea\u662f\u4e00\u4e2a\u8c03\u7528\u4e86 useradd \u547d\u4ee4\u7684\u811a\u672c\u6587\u4ef6\u3002<\/p>\n

\u672c\u6587\u5c06\u8be6\u7ec6\u5206\u6790\u7fa4\u7ec4\u548c\u5bb6\u76ee\u5f55\u76f8\u5173\u7684\u9009\u9879\u3002\u5e76\u4e14\u4ee5\u5b9e\u4f8b\u7684\u65b9\u5f0f\u4ecb\u7ecd\u5e38\u7528\u7684 useradd \u547d\u4ee4\u5199\u6cd5\u3002<\/p>\n

\u8bed\u6cd5\u548c\u57fa\u672c\u9009\u9879<\/strong><\/div>\n

\u6ce8\u610f\uff1a\u672c\u6587\u5e76\u4e0d\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u6587\u6863\uff0c\u6240\u4ee5\u4ec5\u5217\u51fa\u90e8\u5206\u5e38\u7528\u7684\u9009\u9879\u8fdb\u884c\u8bf4\u660e\u3002<\/p>\n

useradd [option] username
\n[option]:
\n-d< \u767b\u5165\u76ee\u5f55> \u6307\u5b9a\u7528\u6237\u767b\u5165\u65f6\u7684\u76ee\u5f55\u3002
\n-g< \u7fa4\u7ec4> \u521d\u59cb\u7fa4\u7ec4\u3002
\n-G< \u7fa4\u7ec4> \u975e\u521d\u59cb\u7fa4\u7ec4\u3002
\n-m \u81ea\u52a8\u521b\u5efa\u7528\u6237\u7684\u5bb6\u76ee\u5f55\u3002
\n-M \u4e0d\u8981\u521b\u5efa\u7528\u6237\u7684\u5bb6\u76ee\u5f55\u3002
\n-N \u4e0d\u8981\u521b\u5efa\u4ee5\u7528\u6237\u540d\u79f0\u4e3a\u540d\u7684\u7fa4\u7ec4\u3002
\n-s \u6307\u5b9a\u7528\u6237\u767b\u5165\u540e\u6240\u4f7f\u7528\u7684shell\u3002<\/p>\n

\u7ec6\u8bf4\u7528\u6237\u7ec4
\n<\/strong><\/span><\/div>\n

\u9996\u5148\u6211\u4eec\u8981\u641e\u6e05\u695a\uff0c\u4ec0\u4e48\u662f\u521d\u59cb\u7fa4\u7ec4\uff1f\u7b80\u5355\u6765\u8bf4\u5728 \/etc\/passwd \u6587\u4ef6\u4e2d\uff0c\u6bcf\u884c\u7684\u7b2c\u56db\u4e2a\u5b57\u6bb5\u6307\u5b9a\u7684\u5c31\u662f\u7528\u6237\u7684\u521d\u59cb\u7fa4\u7ec4\u3002\u7528\u6237\u767b\u5f55\u540e\u7acb\u5373\u5c31\u62e5\u6709\u4e86\u521d\u59cb\u7fa4\u7ec4\u4e2d\u7684\u6743\u9650\u3002<\/p>\n

\u4e0b\u9762\u6211\u4eec\u901a\u8fc7\u4e0d\u540c\u7684\u547d\u4ee4\u6765\u67e5\u770b\u7fa4\u7ec4\u9009\u9879\u7684\u7528\u6cd5\uff1a<\/p>\n

\r\n$ sudo useradd tester1\r\n<\/pre>\n

\u6ca1\u6709\u4f7f\u7528\u4efb\u4f55\u7fa4\u7ec4\u76f8\u5173\u7684\u53c2\u6570\uff0c\u9ed8\u8ba4\u5728\u521b\u5efa\u7528\u6237 tester1 \u7684\u540c\u65f6\u4f1a\u521b\u5efa\u4e00\u4e2a\u540c\u540d\u7684\u7fa4\u7ec4\u3002\u7528\u6237 tester1 \u7684\u521d\u59cb\u7fa4\u7ec4\u5c31\u662f\u8fd9\u4e2a\u65b0\u5efa\u7684\u7fa4\u7ec4\u3002<\/p>\n

\r\n$ sudo useradd tester2 -N\r\n<\/pre>\n

\u8fd9\u6b21\u6211\u4eec\u4f7f\u7528\u4e86 -N \u9009\u9879\uff0c\u5373\u4e0d\u8981\u751f\u6210\u4e0e\u7528\u6237\u540c\u540d\u7684\u7fa4\u7ec4\u3002\u67e5\u770b\u4e0b \/etc\/passwd \u6587\u4ef6\uff0c\u53d1\u73b0 tester2 \u7528\u6237\u7684\u521d\u59cb\u7fa4\u7ec4ID\u662f100\u3002\u8fd9\u4e2a100\u662f\u54ea\u6765\u7684\uff1f\u6709ID\u4e3a100\u7684\u7fa4\u7ec4\u5417\uff1f\u5176\u5b9e100\u4f5c\u4e3a -N \u7684\u9ed8\u8ba4\u503c\u662f\u5199\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u3002\u4e0d\u7ba1\u6709\u6ca1\u6709ID\u4e3a100\u7684\u7fa4\u7ec4\uff0c\u90fd\u662f\u8fd9\u4e2a\u503c\u3002\u5f53\u7136\u6211\u4eec\u4e5f\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u6765\u6539\u53d8\u8fd9\u4e2a\u9ed8\u8ba4\u503c\uff01<\/p>\n

\r\n$ sudo useradd tester3 -g sudo\r\n<\/pre>\n

sudo \u662f\u4e00\u4e2a\u975e\u5e38\u6709\u6743\u52bf\u7684\u7fa4\u7ec4\uff0c\u6211\u51b3\u5b9a\u628a tester3 \u52a0\u5165\u5230\u8fd9\u4e2a\u7fa4\u7ec4\u3002\u597d\uff0c\u73b0\u5728\u53bb\u67e5\u770b\u4e00\u4e0b \/etc\/passwd \u548c \/etc\/group \u6587\u4ef6\uff0c\u770b\u770b\u6709\u6ca1\u6709\u65b0\u7684\u7fa4\u7ec4\u88ab\u521b\u5efa\uff1f tester3 \u7684\u521d\u59cb\u7fa4\u7ec4\u53c8\u662f\u8c01\uff1f\u8fd9\u6b21\u6ca1\u6709\u521b\u5efa\u4e0e tester3 \u540c\u540d\u7684\u7fa4\u7ec4\u3002\u7528\u6237 tester3 \u7684\u521d\u59cb\u7fa4\u7ec4\u53d8\u6210\u4e86 sudo\u3002<\/p>\n

\r\n$ sudo useradd tester4 -G sudo\r\n<\/pre>\n

\u548c\u4e0a\u4e00\u6761\u547d\u4ee4\u76f8\u6bd4\u6211\u4eec\u53ea\u662f\u628a\u5c0f\u5199\u7684g\u66ff\u6362\u6210\u4e86\u5927\u5199\u7684G\u3002\u4f46\u7ed3\u679c\u53ef\u76f8\u5dee\u592a\u591a\u4e86\uff0c\u8bf7\u60a8\u4e00\u5b9a\u8981\u597d\u597d\u7684\u68c0\u67e5 \/etc\/passwd \u548c \/etc\/group \u6587\u4ef6\u3002\u56e0\u4e3a\u8fd9\u6b21\u4e0d\u4ec5\u521b\u5efa\u4e86\u7fa4\u7ec4 tester4\uff0c\u5b83\u8fd8\u662f\u7528\u6237 tester4 \u7684\u521d\u59cb\u7fa4\u7ec4\u3002\u548ctester1 \u7684\u552f\u4e00\u4e0d\u540c\u662f tester4 \u88ab\u52a0\u5165\u4e86 sudo \u7fa4\u7ec4\u3002<\/p>\n

\u5728\u5b9e\u9645\u7684\u4f7f\u7528\u4e2d\uff0ctester3 \u548c tester4 \u7684\u573a\u666f\u90fd\u662f\u6bd4\u8f83\u5e38\u89c1\u7684\uff0c\u9700\u8981\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u8fdb\u884c\u533a\u5206\u3002<\/p>\n

\u7ec6\u8bf4\u5bb6\u76ee\u5f55<\/strong><\/span><\/div>\n

Useradd \u547d\u4ee4\u5bf9\u7528\u6237\u5bb6\u76ee\u5f55\u7684\u5904\u7406\u8ba9\u4eba\u56f0\u60d1\uff0c\u4e0b\u9762\u6211\u4eec\u5c06\u901a\u8fc7\u5b9e\u9a8c\u6765\u4e86\u89e3\u5bb6\u76ee\u5f55\u76f8\u5173\u7684\u4e0d\u540c\u9009\u9879\u7684\u4f7f\u7528\u65b9\u6cd5\uff1a<\/p>\n

\r\n$ sudo useradd tester1\r\n<\/pre>\n

\u8ba9\u6211\u4eec\u91cd\u65b0\u770b\u770b\u521b\u5efa\u7528\u6237 tester1 \u8fd9\u6761\u547d\u4ee4\u3002\u5b83\u4e0d\u4f1a\u4e3a\u7528\u6237 tester1 \u521b\u5efa\u540d\u4e3a tester1 \u7684\u76ee\u5f55\u4f5c\u4e3a\u5bb6\u76ee\u5f55\uff0c\u4f46\u662f\u6211\u4eec\u6253\u5f00 \/etc\/passwd \u6587\u4ef6\uff0c\u53d1\u73b0 tester1 \u7684\u8bb0\u5f55\u4e2d\u5c45\u7136\u5305\u542b\u4e86\u5bb6\u76ee\u5f55 \/home\/tester1\u3002
\ntester1:x:1005:1005::\/home\/tester1:
\n\u8fd9\u8ba9\u4eba\u4e0d\u53ef\u601d\u8bae\uff0c\u4f46\u8fd9\u6761\u547d\u4ee4\u786e\u5b9e\u662f\u8fd9\u4e48\u5b9e\u73b0\u7684\u3002<\/p>\n

\r\n$ sudo useradd -m tester5\r\n<\/pre>\n

\u82e5\u8981\u5728\u521b\u5efa\u7528\u6237\u7684\u540c\u65f6\u521b\u5efa\u7528\u6237\u7684\u5bb6\u76ee\u5f55\uff0c\u5fc5\u987b\u6307\u5b9a -m \u9009\u9879\u3002<\/p>\n

\r\n$ sudo useradd -d \/home\/abc tester6\r\n<\/pre>\n

\u6211\u4eec\u5e0c\u671b\u81ea\u5df1\u6307\u5b9a\u5bb6\u76ee\u5f55\uff0c\u6b64\u65f6\u4e0d\u751f\u6210\u76ee\u5f55 abc<\/p>\n

\r\n$ sudo useradd -d \/home\/abcd -m tester7\r\n<\/pre>\n

\u6b64\u65f6\u751f\u6210\u76ee\u5f55 abcd\uff0c\u5e76\u4e14\u76ee\u5f55\u4e0b\u9ed8\u8ba4\u5b58\u5728\u6587\u4ef6<\/p>\n

\u5e38\u89c1\u7528\u4f8b<\/strong><\/span><\/div>\n

Case 1: \u521b\u5efa\u4e00\u4e2a\u5e26\u6709\u5bb6\u76ee\u5f55\u5e76\u4e14\u53ef\u4ee5\u767b\u5f55 bash \u7684\u7528\u6237<\/p>\n

\r\n$ sudo useradd -m -s \/bin\/bash tester1\r\n<\/pre>\n

Case 2: \u6307\u5b9a\u521b\u5efa\u7528\u6237\u5bb6\u76ee\u5f55\u7684\u8def\u5f84<\/p>\n

\r\n$ sudo useradd -m -d \/home\/xxx tester2\r\n<\/pre>\n

\/home\/xxx\u76ee\u5f55\u4f1a\u88ab\u521b\u5efa\u3002<\/p>\n

Case 3: \u521b\u5efa\u4e00\u4e2a\u6ca1\u6709\u5bb6\u76ee\u5f55\u4e14\u4e0d\u80fd\u767b\u5f55\u7684\u7528\u6237<\/p>\n

\r\n$ sudo useradd -s \/sbin\/nologin tester3\r\n<\/pre>\n

Case 4: \u521b\u5efa\u65f6\u628a\u7528\u6237\u52a0\u5165\u4e0d\u540c\u7684\u7528\u6237\u7ec4<\/p>\n

\r\n$ sudo useradd -m -G xxx,sudo tester4\r\n<\/pre>\n

\u6ce8\u610f\u8fc7\u4e2a\u7ec4\u540d\u4f7f\u7528\u9017\u53f7\u5206\u9694\uff0c\u4e0d\u80fd\u6709\u7a7a\u683c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u8bf4\u660e\uff1a\u672c\u6587\u4e2d\u7684\u6240\u6709\u8bd5\u9a8c\u90fd\u662f\u5728 Ubuntu14.04 \u4e0a\u5b8c\u6210\u3002 \u5728Linux\u4e2d useradd \u547d\u4ee4\u7528\u6765\u521b\u5efa\u6216 […]<\/p>\n","protected":false},"author":63,"featured_media":134471,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-134470","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\/134470","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\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=134470"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/134470\/revisions"}],"predecessor-version":[{"id":134770,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/134470\/revisions\/134770"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/134471"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=134470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=134470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=134470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}