[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 





# Esc to exit insert mode

# :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 user
# sudo useradd -D







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







To create a new user account for Chris Mason named cmason:

# 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

Enter # sudo cat /etc/shadow to display the contents of the /etc/shadow file.

Verify that you can see various information about each user account, including their password hash value and any expiration information.






The !! symbols indicate that the account has a blank password and therefore users are not allowed to log in as that account.

To configure a password for the manderson account
# sudo passwd manderson

Attach a real name to each user account
# sudo usermod -c "Rose Stanley" rstanleyto modify the comment field for the existing rstanley account.

To display the manderson account password expiration information
# sudo chage -l manderson
To set the account expiration for the user to 12/31/2026: 
# sudo chage -E 2026/12/31 manderson 
To view the updated expiration information:
# sudo chage -l manderson 








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











User Profiles

The .bashrc File













The .bash_profile



Comments

Popular posts from this blog

Install Gophish and Start Your Phishing Campaign

Hướng dẫn cách đọc và hiểu thông số firewall - tường lửa

LINUX - MANAGING NETWORK