{"id":65,"date":"2015-03-15T22:59:09","date_gmt":"2015-03-15T14:59:09","guid":{"rendered":"http:\/\/gnonstop.linkpc.net\/~gordon\/?page_id=65"},"modified":"2025-08-24T18:36:45","modified_gmt":"2025-08-24T10:36:45","slug":"users-and-groups-of-linux","status":"publish","type":"page","link":"https:\/\/guerilla.ddns.net\/wp\/?page_id=65","title":{"rendered":"users and groups of linux"},"content":{"rendered":"<h5>\u25cf add a user (\u65b0\u589e\u4f7f\u7528\u8005)<\/h5>\n<pre><code class=\"language-bash\" data-line=\"\">sudo useradd name<\/code><\/pre>\n<p>\u6216\u662f<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">sudo adduser name<\/code><\/pre>\n<p>&nbsp;<br \/>\n\u7bc4\u4f8b:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">sudo adduser --system --no-create-home --group yourusername<\/code><\/pre>\n<p>The <b>&#8211;system<\/b> flag (<b>-r<\/b>) will create a system user &#8211; one which does not have a password, a home dir and is unable to login.<br \/>\n<span style=\"color: #FF0000;\">Q 1st:<\/span> <b>&#8211;no-create-home<\/b> is no need?<br \/>\n<span style=\"color: #FF0000;\">Q 2nd:<\/span> <b>&#8211;group<\/b> is for what?<br \/>\n&nbsp;<\/p>\n<h5>\u25cf modify the username of a user:<\/h5>\n<pre><code class=\"language-bash\" data-line=\"\">sudo usermod -l new_username old_username<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h5>\u25cf To change the password for a user:<\/h5>\n<pre><code class=\"language-bash\" data-line=\"\">sudo passwd username<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h5>\u25cf change the shell for a user:<\/h5>\n<pre><code class=\"language-bash\" data-line=\"\">sudo chsh username<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h5>\u25cf To change the details for a user (for example real name):<\/h5>\n<pre><code class=\"language-bash\" data-line=\"\">sudo chfn username<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h5>\u25cf remove\/delete a user<\/h5>\n<pre><code class=\"language-bash\" data-line=\"\">sudo userdel username<\/code><\/pre>\n<p>&nbsp;<br \/>\nThen to delete the home directory for the deleted user account:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">sudo rm -r \/home\/username<\/code><\/pre>\n<p>&nbsp;<br \/>\nBonus: If you want to delete user&#8217;s home directory\/mails as well<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">sudo deluser --remove-home username<\/code><\/pre>\n<p>and<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">sudo deluser --remove-all-files username<\/code><\/pre>\n<p>will remove the user and all files owned by this user on the whole system.<br \/>\n&nbsp;<\/p>\n<h5>\u25cf list all the groups<\/h5>\n<pre><code class=\"language-bash\" data-line=\"\">cat \/etc\/group<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h5>\u25cf list all the groups of which the current user is a member<\/h5>\n<pre><code class=\"language-bash\" data-line=\"\">groups<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h5>\u25cf list the members of a group<\/h5>\n<pre><code class=\"language-bash\" data-line=\"\">getent group groupname<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h5>\u25cf add a user to a specific group use<\/h5>\n<pre><code class=\"language-bash\" data-line=\"\">sudo usermod -G groupname -a username<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h5>\u25cf remove a user from a specific group<\/h5>\n<pre><code class=\"language-bash\" data-line=\"\">sudo gpasswd -d username groupname<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h5>\u25cf delete a group<\/h5>\n<pre><code class=\"language-bash\" data-line=\"\">sudo groupdel groupname<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<br \/>\n#linux #user #adduser #removeuser #group #addgroup #removegroup<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: right;\">2015\/3\/15<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u25cf add a user (\u65b0\u589e\u4f7f\u7528\u8005) sudo useradd name \u6216\u662f sudo adduser  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-65","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/pages\/65","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=65"}],"version-history":[{"count":19,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/pages\/65\/revisions"}],"predecessor-version":[{"id":3457,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/pages\/65\/revisions\/3457"}],"wp:attachment":[{"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}