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
This sets up a new user with a home directory and some basic settings.
For other Linux versions, try:
sudo useradd -m username
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
If you need to change your own password:
passwd
3. Deleting a User
To remove a user but keep their files:
sudo deluser username
If you want to remove the user and their home directory:
sudo deluser --remove-home username
For RedHat-based systems:
sudo userdel -r username
4. Managing User Groups
Groups help organize users with similar permissions. To add a user to a group:
sudo usermod -aG groupname username
To see which groups a user is in:
groups username
To create a new group:
sudo groupadd groupname
To remove a user from a group:
sudo gpasswd -d username groupname
5. Understanding Linux File Permissions
Files and folders have permissions that control who can read, write, or run them. To check permissions:
ls -l
You'll see something like this:
-rw-r--r-- 1 user group 1234 Jan 1 12:00 file.txt
- 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
To change ownership:
chown user:group filename
6. Switching Users
To switch to another user:
su - username
Or use sudo
to run commands as another user:
sudo -u username command