DEV Community

Cover image for Linux User Management Basics
Madhushan  Herath
Madhushan Herath

Posted on

Linux User Management Basics

Linux User Management Basics: A Beginner's Guide

If you're using Linux, knowing how to manage users is super important, especially if you're running a server or sharing your system with others. It helps you keep things organized and secure. Let’s go over the basics of handling users in Linux!

1. Creating a New User

Adding a new user is easy! If you're on Ubuntu/Debian, use this:

sudo adduser username
Enter fullscreen mode Exit fullscreen mode

This sets up a new user with a home directory and some basic settings.

For other Linux versions, try:

sudo useradd -m username
Enter fullscreen mode Exit fullscreen mode

The -m flag makes sure the home directory is created.

2. Setting and Changing User Passwords

After adding a user, they’ll need a password:

sudo passwd username
Enter fullscreen mode Exit fullscreen mode

If you need to change your own password:

passwd
Enter fullscreen mode Exit fullscreen mode

3. Deleting a User

To remove a user but keep their files:

sudo deluser username
Enter fullscreen mode Exit fullscreen mode

If you want to remove the user and their home directory:

sudo deluser --remove-home username
Enter fullscreen mode Exit fullscreen mode

For RedHat-based systems:

sudo userdel -r username
Enter fullscreen mode Exit fullscreen mode

4. Managing User Groups

Groups help organize users with similar permissions. To add a user to a group:

sudo usermod -aG groupname username
Enter fullscreen mode Exit fullscreen mode

To see which groups a user is in:

groups username
Enter fullscreen mode Exit fullscreen mode

To create a new group:

sudo groupadd groupname
Enter fullscreen mode Exit fullscreen mode

To remove a user from a group:

sudo gpasswd -d username groupname
Enter fullscreen mode Exit fullscreen mode

5. Understanding Linux File Permissions

Files and folders have permissions that control who can read, write, or run them. To check permissions:

ls -l
Enter fullscreen mode Exit fullscreen mode

You'll see something like this:

-rw-r--r-- 1 user group 1234 Jan 1 12:00 file.txt
Enter fullscreen mode Exit fullscreen mode
  • The first character (-) means it's a file (d means directory).
  • The next three (rw-) are for the owner.
  • The next three (r--) are for the group.
  • The last three (r--) are for others.

To change permissions:

chmod 755 filename
Enter fullscreen mode Exit fullscreen mode

To change ownership:

chown user:group filename
Enter fullscreen mode Exit fullscreen mode

6. Switching Users

To switch to another user:

su - username
Enter fullscreen mode Exit fullscreen mode

Or use sudo to run commands as another user:

sudo -u username command
Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay