[LINUX] - MANAGING USERS AND GROUPS
[LINUX] - MANAGING USERS AND GROUPS
Topic A: Assume Superuser Privileges
THE su COMMAND
It helps to switch identity by "substitute user" but retains original user's profile and variables. However, you will be challenged for the password of the switched user.
The SYNTAX of the su command is:
# su [-] [username]
For example:
# su - root: to elevate your credentials
Enter the password of the root user:
The sudo COMMAND
This command enables the server administrator to delegate specific command to specific users, without granting them full privileges on the server.
The syntax of this command is sudo [options] {command}
Instead of using vim or nano, you should use visudo to edit /etc/sudoers. It will verify the syntax of this critical file before committing changes:
# visudo
# Shift + G: to move directly to the last line of the file
# End: to move to the end of the last line
Then, enter the following commands
# insert to enter the command mode
Add a new line at the bottom of the file:
# student01 ALL=(ALL) NOPASSWD:ALL => This grants the student account to execute all commands without you having to switch to the root every time. It also prevents you from having to input your password
# :wq to save and close the file
# sudo /sbin/shutdown -r 15 to test your ability to shutdown the machine
# Ctrl+C
# sudo shutdown -c to interrupt the reboot
Creating User Accounts
View the current default settings for new users
To view the default settings for newly created users:
# less /etc/login.defs
# q to quit
To view files that will be copied to the home directories of newly created user accounts
# ls -a /etc/skel
Create a user
# sudo useradd manderson
To view the new user account
# cat /etc/passwd
# sudo useradd "Chris Mason" cmason
# cat /etc/passwd
To create a new temporary user account for Rose Stanley named rstanley whose contract will end on December 31, 2025 by using the following command:
# sudo useradd -e 2025/12/31 rstanley
Modifying User Accounts
Deleting a User Account
# sudo userdel <username>
Creating, Modifying, and Deleting Groups
wheel GROUP: exercise the administrative privilege of root with less potential for damaging the system. For example, members of the "wheel" group can use the sudo command to avoid having to sign in as the root user.
# usermod -a -G wheel <username>
To create a new group called Graphics:
# sudo groupadd Graphics
To check the presence of the new groups:
# cat /etc/group
To rename the Graphics group to GraphicsDept:
# sudo groupmod -n GraphicsDept Graphics
To add the rstanley account to the GraphicsDept group:
# sudo usermod -aG GraphicsDept rstanley
Querying Users and Groups
To display your login name:
# whoami
To display your login credentials and group membership:
# id
To see what users are currently logged in to the system:
# who
To see what users are currently logged in:
# w
To display a record of recent logins to the system (The last command retrieves information from the /var/log/wtmp file):
# last
Comments
Post a Comment