LAB3 DuyMinh
LAB3 DuyMinh
LAB3 DuyMinh
The purpose of hardening security in user account management is to protect sensitive data,
prevent unauthorized access, and maintain the integrity and availability of systems and
information. This involves implementing various measures to secure user accounts from
potential threats and vulnerabilities.
2. Which command can you use to create a new user account in Linux?
Here is a basic example to create a new user account named newuser:sudo useradd
newuser
However, the useradd command with just the username might not be sufficient for
creating a fully functional user account because it does not create the user's home
directory or set a password. A more comprehensive approach involves using additional
options:
Create Home Directory:To create the user's home directory, use the -m option:
To set the default shell for the user, use the -s option followed by the path to the shell:
After creating the user, you can set the password using the passwd command:
To add the user to a specific group, use the -G option followed by the group name(s):
For example, to create a new user named newuser with a home directory, set the default
shell to /bin/bash, and add them to the developers group, you would use:
After running this command, you would then set the user's password:
3. How do you set a password for a user account using the command line?
To set a password for a user account using the command line in Linux, you can use the
passwd command. The basic syntax for setting a password is:
Here’s a step-by-step example of how to set a password for a user account named
newuser:
Open a terminal.
Type the following command to set or change the password for newuser:
You will be prompted to enter the new password for the user:
Enter the new password and press Enter. You will be prompted to retype the password to
confirm:
Enter the new password again and press Enter. If both entries match, you will see a
message indicating that the password was updated successfully:
Traditionally, the /etc/passwd file is used to keep track of every registered user that has
access to a system. The /etc/passwd file is a colon-separated file that contains the
following information: User name. Encrypted password.
To lock a user account in Linux and prevent the user from logging in, you can use the
passwd command with the -l option. The basic syntax is:
7. Which command allows you to modify user account properties, such as the home
directory or shell?
The 'usermod' command is a powerful utility in Linux used to modify user accounts. It is
used with the basic syntax, usermod [options] username . You can use it to change
various user attributes like user's home directory, login name, and even password expiry
date.
The passwd command changes passwords for user accounts. A normal user may only
change the password for their own account, while the superuser may change the password
for any account. passwd also changes the account or associated password validity period
9. How do you change the password expiration policy for a user account?
To change the password expiration policy for a user account in Linux, you can use the
chage command. This command allows you to configure various password expiration
settings for a user. Here’s how you can use it:
First, you can view the current password expiration settings for a user account by using
the following command:
-E EXPIRE_DATE: Set the account expiration date (in the format YYYY-MM-DD).
The chage command in Linux is used to view and modify user password expiration
information. Its primary purpose is to manage password aging policies, allowing
administrators to enforce password changes and account expirations, which enhances
system security.
Least privilege is the concept and practice of restricting access rights for users,
accounts, and computing processes to only those resources absolutely required
to perform legitimate functions. Privilege itself refers to the authorization to
bypass certain security restraints
The passwd command with the -l (lock) option adds an exclamation mark (!) to the
beginning of the user's encrypted password in the /etc/shadow file, effectively preventing
the user from logging in.
The usermod command with the -L option also locks the user account by adding an
exclamation mark (!) to the password.
sudo usermod -L username
Using the chage command, you can set the account expiration date to a date in the past,
which disables the account.
By changing the user's shell to /sbin/nologin (on most Linux distributions) or /bin/false,
you prevent the user from logging into the system.
To delete a user account in a Linux system, you can use the userdel command. This
command allows administrators to remove user accounts from the system. Here is how to
use it:
The simplest form of the command deletes the user account but leaves the user's home
directory and files intact.
To delete the user account along with the user's home directory and mail spool, use the -r
option.
14. What is the difference between disabling and deleting a user account?
One an account is “deleted”, if it is not used again in the next 14 days, it is a closed
account. Then it can't be opened or operated. Yet, it remains open in Quora for all to see.
Contents are not deleted.
The su command in Linux lets you switch to another user's account or execute
commands as a different user. It's useful for administrative tasks that require
elevated privileges. su is also used to test commands with different user
permissions to ensure the system requires authentication for user switches
17. What is the default shell for a new user account in Linux?
The default shell for a new user account in most Linux distributions is typically /bin/bash.
However, it's worth noting that some distributions might have different default shells
configured. For example:
On Debian-based systems (e.g., Debian, Ubuntu), the default shell for new users is often
/bin/bash.
On Red Hat-based systems (e.g., CentOS, Fedora), the default shell for new users is also
commonly /bin/bash.
On some systems, /bin/sh might be symlinked to another shell like dash or bash, so
/bin/sh behaves like that shell.
To check the default shell for new users on your specific Linux distribution, you can
usually find this information in the system's configuration files, such as
/etc/default/useradd or /etc/login.defs. Additionally, the getent command can be used to
retrieve this information:
This command searches for users whose default shell is set to /bin/bash. You can replace
/bin/bash with the default shell you want to check.
18. How can you enforce password complexity rules for user accounts?
Enforcing password complexity rules for user accounts is essential for enhancing system
security. In Linux systems, you can achieve this by configuring the password policy using
the Pluggable Authentication Modules (PAM) framework and tools like passwd and
chage.
1. Using PAM (Pluggable Authentication Modules):
Add or modify the pam_unix.so line to include the minlen, ucredit, lcredit, dcredit, and
ocredit options to specify password complexity requirements.
2. Using passwd:
The passwd command allows you to set or change a user's password and enforce
complexity rules using the -r option. However, this method might vary depending on your
Linux distribution.
3. Using chage:
The chage command can enforce password aging policies, including minimum password
age, maximum password age, and password history. While it doesn't directly enforce
complexity rules, it can complement other methods.
4. Using /etc/login.defs:
You can also enforce global password policies by modifying the /etc/login.defs file. This
file contains various settings related to user authentication, including password-related
configurations.
The /etc/shadow is a text-based password file. The shadow file stores the hashed
passphrase (or “hash”) format for Linux user account with additional properties
related to the user password. This shadow file is directly accessible only to the
root user
20. Which command can you use to change the group membership of a user account?
To change the group membership of a user account in Linux, you can use the usermod
command. This command is used for modifying user account attributes, including group
membership. Here's how you can use it to change the group membership of a user
account:
Explanation of options:
-g new_group: Specifies the new primary group for the user account.
username: The username of the user account whose group membership you want to
change.