Managing User Access Privileges
Adding and Deleting User Accounts
To add a new user account in Ubuntu 22.04, you can use the adduser
command:
sudo adduser new_username
This will prompt you to set a password for the new user and provide some additional information.
To delete a user account, you can use the deluser
command:
sudo deluser --remove-home old_username
The --remove-home
option will also delete the user's home directory.
Modifying User Privileges
To change a user's group membership, you can use the usermod
command:
sudo usermod -a -G group_name username
The -a
option adds the user to the specified group, and the -G
option specifies the group name.
To grant a user the ability to run commands with elevated privileges using sudo
, you can add the user to the sudo
group:
sudo usermod -a -G sudo username
Managing Group Permissions
Groups in Linux are used to organize users and manage their permissions. You can create new groups using the groupadd
command:
sudo groupadd new_group
To add a user to a group, you can use the usermod
command:
sudo usermod -a -G new_group username
To remove a user from a group, you can use the gpasswd
command:
sudo gpasswd -d username new_group
Applying Permissions to Files and Directories
To change the permissions of a file or directory, you can use the chmod
command:
sudo chmod 755 /path/to/file_or_directory
This sets the permissions to rwxr-xr-x
, where the owner has read, write, and execute permissions, and the group and others have read and execute permissions.