When a user account is created by default with a default password, how do I get a user to change their password when they first log in? To force a user to change their password, use the passwd command. This command is suitable for changing the password with -e or -expire:
# passwd --expire ravi
Then use the chage command to verify the password expiration information of user ravi:
# chage -l ravi
You can see from the chage command output that you must change the user password after running the passwd command. The next time user ravi tries to log in, the system prompts the user to change the password to access the shell.
Run the chage -d 0 username command to set the expiration date of the user's password to January 1, 1970, forcing the user to change the password the next time they log in.
# chage --lastday 0 ravi
or
# chage --lastday 1970-01-01 ravi
Run the chage command to check user ravi password expiration and aging information:
# chage -l ravi
In Linux, if you want to display the real and valid ids of users and groups:
$ id tecmint
The groups command can be used to view the membership of a user group and list all the groups to which the user belongs:
$ groups tecmint
Displays information about users in linux, including details about a specific user or list of users, such as login name, real name, terminal, idle time, login time, and other relevant details. None of the above commands come pre-installed and the finger command can be installed with the default package manager:
$sudo apt install finger [on Debian, Ubuntu, and Mint]
$sudo yum install finger [on RHEL/CentOS/Fedora and Rocky/AlmaLinux]
$sudo emerge -a sys-apps/finger [on Gentoo Linux]
$sudo apk add finger [on Alpine Linux]
$sudo pacman -S finger [on Arch Linux]
$sudo zypper install finger [on OpenSUSE]
Display user's real name, home directory, shell, login name: name time, etc. :
$ finger tecmint
The getent command is used to retrieve information about users, groups, hosts, networks, protocols, and other system entities stored in database files. Get user account details with passwd database and user name:
$ getent passwd tecmint
The grep command can be used to search for patterns or specific text in a file, and then filter and extract lines in the text based on matching patterns. The name grep stands for global regular expression printing.
Use grep to view a specific user from the system account file /etc/passwd:
$ grep -i tecmint /etc/passwd
The IsIogins command displays user information in linux:
$ lslogins -u tecmint
$ lslogins -u
List the current linux logged-in users:
$ users