This repository was archived by the owner on Nov 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Linux Unix add, edit and remove users and groups
Michael Hulse edited this page Mar 7, 2018
·
7 revisions
Add Linux user:
# List local users:
$ cut -d: -f1 /etc/passwd
# Add a new user:
$ sudo adduser myuser
# Remove a user:
$ sudo userdel myuser && rm -r /home/myuser
# Set password:
$ sudo passwd myuser
Changing password for user myuser.
New password: xxxx
Retype new password: xxxxGroups:
# Create new group:
$ sudo groupadd mynewgroup
# View groups for user:
$ groups <username>
# No username will default to your user:
$ groups
# Add user to existing group:
$ sudo usermod -a -G <existing-group> <user>
# Change a user’s primary group:
$ usermod -g groupname username
# View the numerical IDs associated with each group:
$ id
$ id -a # Same as above.
# View the numerical IDs associated with each group:
$ id exampleusername
# Create a New User and Assign a Group in One Command:
$ useradd -G examplegroup exampleusername
# Assign a primary group to a user:
$ usermod -g primarygroupname username
# Assign secondary groups to a user (`-a` keeps already existing secondary groups intact, otherwise they would be removed):
$ usermod -a -G secondarygroupname username
# Add a User to multiple secondary groups:
$ usermod -a -G group1,group2,group3 username
# View All Groups on the System
$ getent group