{"id":16945,"date":"2022-10-14T04:52:18","date_gmt":"2022-10-13T20:52:18","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=16945"},"modified":"2022-10-14T04:52:39","modified_gmt":"2022-10-13T20:52:39","slug":"user-add-del","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/user-add-del.html","title":{"rendered":"\u7b80\u5355\u8bed\u53e5\u5b9e\u73b0\u7528\u6237\u6dfb\u52a0\u3001\u5220\u9664"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u672c\u4eba\u82cf\u5c0f\u767d\uff0c\u4e00\u540d\u521a\u521a\u8de8\u5165linux\u4e16\u754c\u7684\u5c0f\u767d\u83dc\u3002\u6700\u8fd1\u4e00\u76f4\u901a\u8fc7\u300alinux\u5c31\u8be5\u8fd9\u4e48\u5b66\u300b\u5b66\u4e60linux\u77e5\u8bc6\uff0c\u524d\u51e0\u5929\u5728\u7f51\u4e0a\u770b\u5230\u4e86\u4e00\u5219\u5173\u4e8e\u666e\u901a\u7528\u6237\u6dfb\u52a0\u3001\u5220\u9664shell\u811a\u672c\u547d\u4ee4\u7684\u9898\u76ee\uff0c\u5f53\u65f6\u81ea\u5df1\u4e0d\u4f1a\u7f16\u5199\uff0c\u4f46\u662f\u628a\u9898\u76ee\u8bb0\u5f55\u4e86\u4e0b\u6765\uff01\u540e\u6765\u901a\u8fc7\u5b66\u4e60\u300alinux\u5c31\u8be5\u8fd9\u4e48\u5b66\u300b\uff0c\u5b8c\u6210\u4e86\u9898\u76ee\u6240\u9700\u3002\u5e0c\u671b\u9700\u8005\u80fd\u770b\u5230\uff0c\u540c\u65f6\u6709\u4ec0\u4e48\u4e0d\u6b63\u786e\u7684\u5730\u65b9\u5e0c\u671b\u5927\u725b\u4eec\u80fd\u6307\u6b63\u7559\u8a00\uff01<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u9898\u76ee\u8981\u6c42\uff1a<\/strong><\/div>\n
\n\u7f16\u8f91shell\u811a\u672c\u547d\u4ee4\uff0c\u5b9e\u73b0\u666e\u901a\u7528\u6237\u7684\u6dfb\u52a0\u4e0e\u5220\u9664\u3002
\n\u8981\u6c42:
\n1.\u6dfb\u52a0\uff08\u5220\u9664\uff09\u666e\u901a\u7528\u6237\u662f\u8981\u67e5\u8be2\u666e\u901a\u7528\u6237\u662f\u5426\u5df2\u5b58\u5728\u3002
\n2.\u6dfb\u52a0\uff08\u5220\u9664\uff09\u8981\u5b9e\u73b0\u5faa\u73af\u8be2\u95ee\n<\/div>\n
\u5177\u4f53\u4ee3\u7801\u5982\u4e0b\uff1a<\/strong><\/div>\n
#!\/bin\/bash\r\nread -p \"\u662f\u5426\u8981\u6dfb\u52a0\u7528\u6237\uff1f \u662f\uff080\uff09\u5426\uff081\uff09\" USERADD  \r\n<\/pre>\n

\u9009\u62e9\u64cd\u4f5c\u7c7b\u578b\u2014\u2014\u6dfb\u52a0\u7528\u6237\/\u5220\u9664\u7528\u6237<\/p>\n

\u6dfb\u52a0\u7528\u6237\u4ee3\u7801<\/strong><\/span><\/div>\n
if [ $USERADD -eq 0 ]\r\nthen\r\nC=1\r\nwhile [ $C -eq 1 ]\r\ndo\r\nread -p \"\u8bf7\u8f93\u5165\u6dfb\u52a0\u8d26\u6237\u8d26\u6237\u540d:\" UNAME  #\u6dfb\u52a0\u7528\u6237\u540d#\r\nid $UNAME &> \/dev\/null    #\u67e5\u770b\u7528\u6237\u662f\u5426\u5b58\u5728#\r\nif [ $? -eq 0 ]\r\nthen\r\necho \"\u8d26\u6237\u4ee5\u5b58\u5728\uff01 \"\r\nelse \r\nread -p \"\u8bf7\u8f93\u5165\u6dfb\u52a0\u8d26\u6237\u5bc6\u7801:\" PASSWD     #\u6dfb\u52a0\u5bc6\u7801#\r\nuseradd $UNAME &> \/dev\/null      #\u521b\u5efa\u7528\u6237#\r\necho \"$PASSWD\" | passwd --stdin $UNAME &> \/dev\/null    #\u521b\u5efa\u7528\u6237\u5bc6\u7801#\r\n<\/pre>\n

\u6ce8\u610f\u5728\"$PASSWD\"\u4e2d\u5207\u52ff\u6dfb\u52a0\u7a7a\u683c\uff0c\u5426\u5219\u5bc6\u7801\u4e2d\u4f1a\u5e26\u6709\u7a7a\u683c\uff01<\/p>\n

if [ $? -eq 0 ]\r\nthen \r\necho \" $UNAME \u521b\u5efa\u6210\u529f\uff01 \"\r\nelse\r\necho \" $UNAME \u521b\u5efa\u5931\u8d25\uff01 \"\r\nfi\r\nfi\r\nread -p \"\u60a8\u662f\u5426\u8fd8\u7ee7\u7eed\u6dfb\u52a0\uff1f\u662f\uff081\uff09\u5426\uff080\uff09\" C   #\u8bbe\u5b9a\u53d8\u91cf\u201cC\u201d\u4ee5\u5b9e\u73b0\u5220\u9664\u4ee3\u7801\u5faa\u73af\u6267\u884c#\r\ndone\r\n<\/pre>\n
\u5220\u9664\u7528\u6237\u4ee3\u7801<\/strong><\/span><\/div>\n

\"\u786e\u5b9a\u8981\u5220\u9664\u7528\u6237\"<\/p>\n

else\r\nDEL=1\r\nwhile [ $DEL -eq 1 ]\r\ndo\r\nread -p \"\u8bf7\u8f93\u5165\u8981\u5220\u9664\u7684\u7528\u6237\u540d\uff1a\" UNAME   #\u8981\u5220\u9664\u7684\u7528\u6237\u540d#\r\nid $UNAME &> \/dev\/null\r\nif [ $? -eq 0 ]  #\u5220\u9664\u7528\u6237\u67e5\u8be2\u662f\u5426\u5b58\u5728#\r\nthen\r\nuserdel -r $UNAME     #\u5220\u9664\u7528\u6237#\r\necho \" $UNAME \u5220\u9664\u6210\u529f\uff01 \"\r\nelse\r\necho \"\u672a\u627e\u5230\u7528\u6237$UNAME\uff01\"\r\nfi\r\nread -p \"\u60a8\u662f\u5426\u7ee7\u7eed\uff1f\u662f\uff081\uff09\u5426\uff080\uff09\" DEL   #\u8bbe\u5b9a\u53d8\u91cf\u201cDEL\u201d\u4ee5\u5b9e\u73b0\u5220\u9664\u4ee3\u7801\u5faa\u73af\u6267\u884c#\r\ndone\r\nfi\r\n\r\n<\/pre>\n

\u672c\u6587\u539f\u521b\u5730\u5740\uff1ahttp:\/\/lrxjmw.cn\/user-add-del.html<\/a>\u4f5c\u8005\uff1a\u82cf\u897f\u4e91\uff0c\u5ba1\u6838\u5458\uff1a\u5cb3\u6c38<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb \u672c\u4eba\u82cf\u5c0f\u767d\uff0c\u4e00\u540d\u521a\u521a\u8de8\u5165linux\u4e16\u754c\u7684\u5c0f\u767d\u83dc\u3002\u6700\u8fd1\u4e00\u76f4\u901a\u8fc7\u300alinux\u5c31\u8be5\u8fd9\u4e48\u5b66\u300b\u5b66\u4e60linux\u77e5\u8bc6\uff0c […]<\/p>\n","protected":false},"author":63,"featured_media":16956,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-16945","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\/16945","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=16945"}],"version-history":[{"count":19,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/16945\/revisions"}],"predecessor-version":[{"id":254659,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/16945\/revisions\/254659"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/16956"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=16945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=16945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=16945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}