Linux user management

Thu, 19 Jun 2025 14:04:16 GMT

Modifying user settings isn't something I do everyday but it is necessary occasionally

You can add a user with the useradd command

usermod is useful for working on a current users priveleges.

The most common use I have for it is adding my user to a group for additional priveleges
make sure to use the -a or you will remove them from other groups

usermod -a -G groupname username

For example we want to add Ted to the foo group

usermod -a -G foo Ted

You can see all the available usergroups in your /etc/group fiile

Other usermod functions:

1 Change a users primary group
usermod -g groupname username

2. Set an expiration date for a user account
usermod -e YYYY-MM-DD username

this is useful if you want a friend to have temporary access to your machine

3. Change users home directory
usermod -d filepath username

4. change users login name
usermod -l newusername currentusername

5. Lock a user account to prevent them from logging in

usermod -L username

To unlock them

usermod -U username

6. change user shell

usermod -s shell path username

for example

usermod -s /bin/bash Ted
will set teds shell to bash

Associated command to usermod

id username
will give you info on the user such as uuid groups etc.