Debian 13 Tutorial / Manage Users, Groups, sudo and File Permissions
Create regular Debian 13 users with adduser, append supplementary groups with usermod -aG, and grant administrative access separately through sudo policy. File access depends on numeric user and group IDs plus permissions on the file and its parent directories. This lab creates two separate accounts, compares allowed and denied shared-file access, checks sudo policy and then removes the lab resources.
Check the Administrator Account and Numeric IDs
Log in to a dedicated VM with an administrator account that can use sudo. This practice does not involve deleting the current administrator or changing that account's groups. The actual verification was performed on a minimal server with Debian 13.7, adduser 3.152, and sudo 1.9.16p2.
whoami
id
getent passwd "$(whoami)"
getent group sudo
sudo -v
When sudo prompts for a password, enter the password of the currently logged-in administrator. It is normal that characters are not displayed while typing. sudo -v must succeed before proceeding with further administrative tasks. On servers without sudo, you must first prepare privileges with the existing root administrator or recovery console, and an account without privileges cannot add itself to the sudo group.
| Item | Meaning | What to check |
|---|---|---|
| UID | Numeric ID identifying the user | The lab administrator had UID 1000. Do not assume that a new account will receive a particular number. |
| Primary GID | The account’s primary group identifier | adduser usually also creates a default group with the same name as the user. |
| Supplementary groups | Additional group memberships | Shared work groups and sudo administrator groups have different purposes. |
getent uses the system’s user and group lookup settings. It can check for name collisions not only for local accounts but also on servers connected to the organization’s directory service. Do not edit /etc/passwd to add accounts or duplicate UIDs with existing users.
Create Lab Accounts with Password Login Disabled
First verify that the lfeditor and lfvisitor accounts, lfeditors group and /srv/lf-team-demo path do not already exist. If an account or group query returns an entry, or the path test fails, stop and choose unused names. A nonzero getent exit status is expected when the requested name is absent; the final test succeeds only when the path does not exist.
getent passwd lfeditor
getent passwd lfvisitor
getent group lfeditors
sudo test ! -e /srv/lf-team-demo
After confirming that there are no existing entries, create the two accounts and the shared group. --disabled-password disables password authentication without creating a reusable example password. In this article, password login is not needed because the administrator reproduces the user's privileges using sudo -u.
sudo adduser --disabled-password --comment '' lfeditor
sudo adduser --disabled-password --comment '' lfvisitor
sudo addgroup lfeditors
sudo usermod -aG lfeditors lfeditor
id lfeditor
getent passwd lfeditor
Check with id lfeditor whether lfeditors has been added, and that the default group lfeditor and the existing secondary groups are maintained. The Debian adduser manual explains the administrative layer for Debian that prepares home directories and account defaults. It should not be assumed to provide the same low-level useradd options and default behavior.
If the account is for a real person logging in with a password, the administrator runs sudo passwd lfeditor to set a unique password for that user and confirms it with a separate login. Do not put passwords or hashes in command lines, documents, or screenshots. Disabling the password does not mean all access to the account is blocked; other authentication methods, such as configured SSH keys, must be managed separately.
The usermod manual explains that -G specifies the supplementary group list, and -a is the option to add to the existing list. Running usermod -G lfeditors lfeditor without -a can cause loss of existing supplementary groups such as sudo, so do not drop the -a option.
Create a Shared Directory and Check Access
The administrator creates a dedicated directory and sets the group to lfeditors. In 2770, the first 2 is the setgid attribute of the directory, ensuring that new items inherit the directory's group. The following 770 allows read/write/execute for the owner and group and denies access to other users.
sudo install -d -o root -g lfeditors -m 2770 /srv/lf-team-demo
sudo -u lfeditor sh -c 'umask 0002; printf "team note\n" > /srv/lf-team-demo/note.txt'
stat -c '%a %U %G %n' /srv/lf-team-demo /srv/lf-team-demo/note.txt
sudo -u lfeditor cat /srv/lf-team-demo/note.txt
sudo -u lfvisitor cat /srv/lf-team-demo/note.txt
The sudo authentication for this command is performed by the existing administrator, and only the file creation command is executed with the lfeditor’s privileges. This is not a command to test the new account's password authentication. Output redirection must be done within sh -c for the file to be opened with that user's permissions. Prefixing a command with sudo does not elevate a redirection performed by the current shell.
2770 root lfeditors /srv/lf-team-demo
664 lfeditor lfeditors /srv/lf-team-demo/note.txt
In the practice, lfeditor could read the team note, while lfvisitor was denied with Permission denied. Although the file mode is 664 and other users have the read bit, access is not possible without execute permission on the parent directory. umask 0002 is the value restricting new file permissions in this subshell, and setgid itself does not automatically grant group write permissions.
Read permission on a directory relates to listing names, write permission allows creating and deleting items, and the execute bit relates to entering and navigating the path. In configurations where the shared directory is given write and execute permissions, other people's files can also be deleted, so if document retention policies are necessary, they should be designed separately. Simply changing the owner to root does not prevent deletion in the parent directory.
Compare Denied and Allowed Group Writes
Change the owner of the same file to root so that lfeditor can access it with group permission. Then change only the mode from 640 to 660. This comparison is to check which permission – owner, group, or others – applies.
sudo chown root:lfeditors /srv/lf-team-demo/note.txt
sudo chmod 640 /srv/lf-team-demo/note.txt
sudo -u lfeditor sh -c 'printf "blocked\n" >> /srv/lf-team-demo/note.txt'
With 640, the root owner can read and write, but the lfeditors group can only read. Therefore, the last command should result in Permission denied. The denied line will not be added to the file. Then, enable only the group write bit.
sudo chmod 660 /srv/lf-team-demo/note.txt
sudo -u lfeditor sh -c 'printf "allowed\n" >> /srv/lf-team-demo/note.txt'
sudo cat /srv/lf-team-demo/note.txt
The file should now contain the two lines shown below. In the numeric modes described by the chmod manual, read contributes 4, write 2 and execute 1. Investigate the actual account and each path component instead of applying chmod -R 777 to a whole directory. Production systems may also apply access control lists (ACLs) and security-module policies beyond these basic mode bits.
team note
allowed
If access differs from expectations, check the user, parent, and file in the order of id lfeditor, ls -ld /srv /srv/lf-team-demo, ls -l /srv/lf-team-demo/note.txt. Even if the last file has permissions, it can be blocked by the parent.
Grant and Check sudo Group Membership
There is no need to give administrative privileges to someone who only needs shared file editing permissions. The following is a temporary exercise to understand how to add a sudo administrator. In the default Debian sudo policy, the sudo group is allowed to execute all commands, so it should only be granted to trusted administrators.
sudo usermod -aG sudo lfeditor
id lfeditor
sudo visudo -c
sudo -l -U lfeditor
In the practice environment, visudo returned parsed OK, and the lfeditor policy showed (ALL : ALL) ALL. This is the result of a sudo policy query and does not replace the success of the user’s login/password authentication. When using it as an actual administrator, prepare a unique authentication method, and while maintaining an existing administrator session, execute id, sudo -v, sudo id -u in a new login to check if the final result is 0.
The command id lfeditor queries the current account database, while id without arguments reports the credentials of the running session. Sessions opened before adding a group may retain the previous group list, so you need to log in completely anew. When editing sudo policies according to the visudo manual, use the syntax-checking function rather than blindly modifying the file in a normal editor. In this exercise, we do not change the existing sudoers file.
After verification, remove the new lab account from the sudo group. Do not substitute your existing administrator’s username in this removal command.
sudo gpasswd -d lfeditor sudo
sudo -l -U lfeditor
With only the default sudo policy, the policy query should now report that lfeditor is not allowed to run sudo. Other sudoers rules can grant access independently of group membership, so removing the group is not always enough to revoke all privileges. Review existing sessions and processes separately.
Test Group Removal and Clean Up the Lab
Temporarily remove the user from a shared group to verify that a new command invocation as that user is denied, then add it back. The gpasswd -d option removes the specified user from the local group.
sudo gpasswd -d lfeditor lfeditors
sudo -u lfeditor cat /srv/lf-team-demo/note.txt
sudo usermod -aG lfeditors lfeditor
sudo -u lfeditor cat /srv/lf-team-demo/note.txt
The first query is denied, and after adding it back, two lines should be read. On a dedicated VM, we confirmed this allow/deny comparison, sudo policy checks, and even account and file cleanup. It should not be interpreted as logging in via SSH with a new account without a password.
Cleanup applies only to newly created accounts and directories in this article. First, check the paths and contents, and if there are any necessary files, store them elsewhere. If the account was reused, do not execute the home deletion command.
sudo ls -la /srv/lf-team-demo
sudo test "$(sudo readlink -f /srv/lf-team-demo)" = /srv/lf-team-demo && sudo rm -r -- /srv/lf-team-demo
sudo deluser --remove-home lfeditor
sudo deluser --remove-home lfvisitor
sudo delgroup lfeditors
getent passwd lfeditor
getent passwd lfvisitor
getent group lfeditors
No output from the final getent queries confirms that these names have been removed. Deleting an account does not automatically delete files owned by its UID outside the home directory. Before removing a real employee account, review file ownership, running tasks, service dependencies, SSH authentication and handover of work materials.




