Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Commands for viewing and managing user passwords under Linux

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "commands for viewing and managing user passwords under Linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

View users

A) to view the currently logged in user

The code is as follows:

[root@krlcgcms01 ~] # w

Function description: displays the user information currently logged in to the system.

Grammar: W [- fhlsuV] [user name]

Add: by executing this instruction, you can know who are currently logged in to the system and the programs they are executing. Execute w separately

The directive displays all users, or you can specify a user name to display only information about a user.

Parameters:

-f turns on or off showing where the user logs in to the system.

-h does not display the title information column of each field.

-l uses a detailed format list, which is the default value.

-s uses a concise format list and does not show the login time of the user, the CPU time spent by the terminal phase jobs and programs.

-u ignores the name of the executing program and the information that the program takes CPU time.

-V displays version information.

The code is as follows:

[root@krlcgcms01 ~] # who

Function description: displays the user information currently logged in to the system.

Grammar: who [- Himqsw] [--help] [--version] [am I] [record file]

Additional note: execute this instruction to know which users are currently logged in to the system. Executing the who instruction alone will list the login account, the terminal used, the login time and where you are logged in or which X monitor you are using.

Parameters:

-H or-- heading displays the header information column of each field.

-I or-u or-- idle shows idle time, and if the user takes any action within the previous minute, it will be marked "." If the user has not taken any action for more than 24 hours, the string "old" is marked.

-m this parameter has the same effect as the specified "am I" string.

-Q or-- count displays only the account name and total number of people logged in to the system.

-s this parameter will be ignored and will not be processed, and will only be responsible for solving the compatibility problem of other versions of the who directive.

-w or-T or-- mesg or-- message or-- writable displays the user's information status bar.

-- help online help.

-- version displays version information.

B), check your user name

The code is as follows:

[root@krlcgcms01 ~] # whoami

Function description: first it seems that the user name.

Grammar: whoami [--help] [--version]

Supplementary note: displays its own user name, and this instruction is equivalent to the execution of the "id-un" instruction.

Parameters:

-- help online help.

-- version displays version information.

C) to view individual user information

The code is as follows:

[root@krlcgcms01 ~] # finger apacheuser

The function of the finger command is to query the user's information, which usually displays the user name, home directory, stagnation time, login time, login shell and other information of a user in the system. If you want to query user information on a remote machine, you need to follow the user name with "@ hostname" in the format of [username @ hostname], but the network host you want to query needs to run the finger daemon.

The general format of the command is:

Finger [option] [user] [user @ host]

The options in the command have the following meanings:

-s displays the user's registration name, actual name, terminal name, write status, stagnation time, login time and other information.

In addition to the information displayed with the-s option, it also displays information such as the user's home directory, login shell, mail status, and the contents of .plan, .project, and .forward files under the user's home directory.

-p is the same as the-l option except that the .plan file and .project file are not displayed.

Use the finger command on the local machine.

The code is as follows:

$finger xxq

Login: xxq Name:

Directory: / home/xxq Shell: / bin/bash

Last login Thu Jan 1 21:43 (CST) on tty1

No mail.

No Plan.

$finger

Login Name Tty Idle Login Time Office Office Phone

Root root * 1 28 Nov 25 09:17

……

[root@krlcgcms01 ~] # id apacheuser

D) to view the user login record

The code is as follows:

[root@krlcgcms01 ~] # last to view user records of successful login

[root@krlcgcms01 ~] # lastb to view user records with unsuccessful login

E), view all users

The code is as follows:

[root@krlcgcms01] # cut-d:-f 1 / etc/passwd

[root@krlcgcms01 ~] # cat / etc/passwd | awk-F\:'{print $1}'

User password management

One of the important contents of user management is the management of user password. When the user account was first created without a password, it was locked by the system and cannot be used. It must be assigned a password before it can be used, even if it is an empty password.

The Shell command to specify and modify a user password is passwd. The ultimate user can specify passwords for himself and other users, and ordinary users can only change their own passwords. The format of the command is:

Code:

Passwd option user name

Available options:

-l lock password, that is, disable the account.

The-u password is unlocked.

-d make the account without a password.

-f forces the user to change the password the next time he logs in.

If the default user name is used, the password of the current user is modified.

For example, assuming that the current user is sam, the following command modifies the user's own password:

The code is as follows:

$passwd

Old password:*

New password:*

Re-enter new password:*

If you are the ultimate user, you can specify the password of any user in the following form:

The code is as follows:

# passwd sam

New password:*

Re-enter new password:*

When an ordinary user modifies his own password, the passwd command will ask the original password first, and then require the user to enter the new password twice after verification. If the password entered twice is the same, the password will be assigned to the user. When the end user assigns a password to the user, he does not need to know the original password. For security reasons, users should choose more complex passwords, preferably using no less than 8-digit passwords, which contain uppercase, lowercase letters and numbers, and should be different from names, birthdays, etc.

When you specify an empty password for the user, execute the following form of command:

Code:

The code is as follows:

# passwd-d sam

This command removes the password for user sam so that the next time user sam logs in, the system no longer asks for the password.

The passwd command can also lock a user out of login with the-l (lock) option, for example:

Code:

The code is as follows:

# passwd-l sam

This is the end of the content of "commands for viewing and managing user passwords under Linux". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report