# Managing Users and Permissions on Linux<

Managing Users and Permissions on Linux< – Server administration and Linux knowledge from NexoraHost.

This guide shows you how to create and manage users on your Linux server and assign the appropriate permissions. Clean user management is essential for your server's security.

**Note:** Detailed subpages on security and advanced topics can be found in the left navigation.

## Why Multiple Users?

    - **Security:** Don't do everything as root – otherwise the entire system is affected by mistakes
- **Access control:** Each user only sees their own files
- **Traceability:** Who made which changes?

## Creating and Managing Users

### Create a New User

`# Create user with home directory
adduser username

# Or with useradd (more options)
useradd -m -s /bin/bash username

# Set password
passwd username`

### Add Users to Groups

`# Add to sudo group (admin rights)
usermod -aG sudo username

# Add to a specific group
usermod -aG groupname username

# Show groups of a user
groups username`

### List and Delete Users

`# Show all users
cat /etc/passwd

# Only "real" users (with shell)
grep -v /nologin /etc/passwd

# Delete user (with home directory)
userdel -r username`

## Understanding File Permissions

`-rwxr-xr-- 1 user group 1024 May 28 12:00 file.txt
 ─┬─ ─┬─ ─┬─
  │   │   └── Permissions for others (Others)
  │   └────── Permissions for the group (Group)
  └────────── Permissions for the owner (Owner)`

    - **r** = Read – value: 4
- **w** = Write – value: 2
- **x** = Execute – value: 1

### Change Permissions with chmod

`# File readable and writable for owner, readable for group and others
chmod 644 file.txt

# Folder: owner has all rights, group and others can read and enter
chmod 755 folder

# Make script executable
chmod +x script.sh

# Recursively for all files in a folder
chmod -R 755 /var/www`

### Change Owner with chown

`# Change owner and group
chown user:group file.txt

# Recursively for an entire folder
chown -R www-data:www-data /var/www`

## Important System Users

    
        User
        Purpose
    

    
        **root**
        Administrator – only use for system tasks
    

    
        **www-data**
        Web server (Apache/Nginx) – website files belong to this user
    

    
        **mysql**
        Database server – database files belong to this user
    

## Common Problems

**"Permission denied" despite correct permissions:**

    - Check if the parent folder is readable – the path must be accessible from top to bottom
- Check permissions of all parent folders with `ls -la /path/to/folder`

**sudo not working:**

    - Is the user in the sudo group? `groups username`
- After adding to the group: The user must log out and log back in

*Detailed guides on security and advanced topics can be found in the articles in the left navigation.*
