[Comprehensive explanation of Linux commands] 211. Detailed explanation of the usage of passwd, a Linux system command

passwd

Used to allow users to change their passwords

Additional information

passwdThe command is used to set the user's authentication information, including user password, password expiration time, etc. System administrators can use it to manage system user passwords. Only administrators can specify user names, and general users can only change their own passwords.

grammar

passwd [选项] [参数]

Options

  • -d: Delete the password, only system administrators can use it;
  • -f: Enforcement;
  • -k: The setting can only be updated after the password expires;
  • -l: Lock password;
  • -s: Lists password-related information, which can only be used by system administrators;
  • -u: Unlock a locked account.

parameter

  • 用户名: User name that requires setting password.

knowledge expansion

Files related to user and group account information

Store user information:

  • /etc/passwd
  • /etc/shadow

Store group information:

  • /etc/group
  • /etc/gshadow

User information file analysis (separate each item with:)

For example:jack:X:503:504:::/home/jack/:/bin/bash

  • jack:username
  • X: Password, password
  • 503: User ID (0 represents root, ordinary new users start from 500)
  • 504:group
  • ::describe
  • /home/jack/:User home directory
  • /bin/bash:User default Shell

Group information file analysis

For example:jack:$!$:???:13801:0:99999:7:*:*:

  • jack:group name
  • $!$: Encrypted password
  • 13801: The number of days between the creation date and today
  • 0: Minimum number of digits in password
  • 99999: User password
  • 7: Reminder when 7 days are up
  • *: Disabled days
  • *:Expiration days

Example

If you are an ordinary user, passwdyou can only change your own password. If you want to create a password for the new user after creating a new user, use passwdthe user name. Note that you must create it with the permissions of the root user.

[root@localhost ~]# passwd linuxde     # 更改或创建linuxde用户的密码;
Changing password for user linuxde.
New UNIX password:           # 请输入新密码;
Retype new UNIX password:    # 再输入一次;
passwd: all authentication tokens updated successfully.  # 成功;

If ordinary users want to change their passwords, passwdthey can run it directly. For example, the current operating user is linuxde.

[linuxde@localhost ~]$ passwd
Changing password for user linuxde.  # 更改linuxde用户的密码;
(current) UNIX password:    # 请输入当前密码;
New UNIX password:          # 请输入新密码;
Retype new UNIX password:   # 确认新密码;
passwd: all authentication tokens updated successfully.  # 更改成功;

For example, if we prevent a user from changing their password, we can use -lthe option to lock it:

[root@localhost ~]# passwd -l linuxde     # 锁定用户linuxde不能更改密码;
Locking password for user linuxde.
passwd: Success            # 锁定成功;
[linuxde@localhost ~]$ su linuxde    # 通过su切换到linuxde用户;
[linuxde@localhost ~]$ passwd       # linuxde来更改密码;
Changing password for user linuxde.
Changing password for linuxde
(current) UNIX password:           # 输入linuxde的当前密码;
passwd: Authentication token manipulation error      # 失败,不能更改密码;

An example of a recurrence:

[root@localhost ~]# passwd -d linuxde   # 清除linuxde用户密码;
Removing password for user linuxde.
passwd: Success                          # 清除成功;
[root@localhost ~]# passwd -S linuxde     # 查询linuxde用户密码状态;
Empty password.                          # 空密码,也就是没有密码;
注意:当我们清除一个用户的密码时,登录时就无需密码,这一点要加以注意。

Learn from scratchpython

[Learn python from scratch] 92. Use Python’s requests library to send HTTP requests and process responses
[Learn python from scratch] 91. Use decorators and dictionaries to manage request paths in a simple web application
[Learn python from scratch] 93. Use dictionary management Request path
[Learn python from scratch] 89. Use WSGI to build a simple and efficient Web server
[Learn python from scratch] 88. Detailed explanation of WSGI interface: realize simple and efficient web development
[Learn python from scratch] 87. Manually build an HTTP server in Python Implementation and multi-threaded concurrent processing
[Learn python from scratch] 86. In-depth understanding of the HTTP protocol and its role in browser and server communication
[Learn python from scratch] 85. Application of parallel computing technology in Python process pool
[Learn python from scratch] ] 84. In-depth understanding of threads and processes
[Learn python from scratch] 83. Python multi-process programming and the use of process pools
[Learn python from scratch] 82. Chat program implementation based on multi-threading
[Learn python from scratch] 81. Python more Application of thread communication and queue
[Learn python from scratch] 80. Thread access to global variables and thread safety issues
[Learn python from scratch] 79. Thread access to global variables and thread safety issues
[Learn python from scratch] 78. File download case
[ Learn python from scratch] 77. TCP server programming and precautions
[learn python from scratch] 76. Server and client: key components of network communication
[learn python from scratch] 75. TCP protocol: reliable connection-oriented transmission Layer communication protocol
[Learn python from scratch] 74. UDP network program: detailed explanation of port issues and binding information
[Learn python from scratch] 73. UDP network program - sending data
[Learn python from scratch] 72. In-depth understanding of Socket communication and creation Socket method
[Learn python from scratch] 71. Network ports and their functions
[Learn python from scratch] 70. Network communication methods and their applications: from direct communication to routers connecting multiple networks
[Learn python from scratch] 69. Network communication and IP address classification analysis
[Learn python from scratch] 68. Greedy and non-greedy modes in Python regular expressions
[Learn python from scratch] 67. The re module in Python: regular replacement and advanced matching technology
[Learn from scratch] python ] 66. In-depth understanding of regular expressions: a powerful tool for pattern matching and text processing
[learn python from scratch] 65. Detailed explanation of Python regular expression modifiers and their applications
[learn python from scratch] 64. re. in Python regular expressions. Detailed explanation of the use of the compile method
[Learn python from scratch] 63. Introduction to the re.Match class and its attributes and methods in regular expressions
[Learn python from scratch] 62. Python regular expressions: a powerful string matching tool
[From scratch Learn python] 61. Detailed explanation and application examples of property attributes in Python
[learn python from scratch] 60. Exploration generator: a flexible tool for iteration
[learn python from scratch] 59. Iterator: an efficient tool for optimizing data traversal
[learn python from scratch] Learn python] 58. Custom exceptions in Python and methods of raising exceptions
[Learn python from scratch] 57. Use the with keyword in Python to correctly close resources
[Learn python from scratch] 56. The importance of exception handling in programming and application
[Learn python from scratch] 55. Serialization and deserialization in Python, application of JSON and pickle module
[Learn python from scratch] 54. Write data in memory
[Learn python from scratch] 53. CSV file and Python's CSV module
[Learn python from scratch] 52. Reading and writing files - Python file operation guide
[Learn python from scratch] 51. Opening and closing files and their application in Python
[Learn python from scratch] 49. Python Object-related built-in functions and their usage
[Learn python from scratch] 48. Detailed explanation of inheritance and multiple inheritance in Python
[Learn python from scratch] 47. The concept and basic use of inheritance in object-oriented programming
[Learn python from scratch] 46 . __new__ and __init__ method analysis and singleton design pattern in Python
[Learn python from scratch] 45. Class methods and static methods in Python
[Learn python from scratch] 44. Private attributes and Method
[Learn python from scratch] 43. Instance attributes and class attributes in Python object-oriented programming
[Learn python from scratch] 42. Built-in attributes and methods in Python
[Learn python from scratch] 41. Python magic method (2)
[ Learn python from scratch】40. Python magic method (1)
【Learn python from scratch】39. Basic object-oriented syntax and application examples
【Learn python from scratch】38. How to use and import Python packages
【Learn python from scratch】37 .The use and precautions of Python custom modules
[Learn python from scratch] 36. Methods and techniques of using pip for third-party package management in Python
[Learn python from scratch] 35. Python common system modules and their usage
[Learn from scratch] python ] 34. Detailed explanation of the import and use of Python modules
[Learn python from scratch] 33. The role of decorators (2)
[Learn python from scratch] 32. The role of decorators (1)
[Learn python from scratch] 31. In-depth understanding of higher-order functions and closures in Python
[Learn python from scratch] 30. In-depth understanding of recursive functions and anonymous functions
[Learn python from scratch] 29. "Detailed explanation of function parameters" - Understand the different uses of Python function parameters
[Learn python from scratch] 28. Local variables and global variables in Python
[Learn python from scratch] 27. Use of Python functions and nested calls
[Learn python from scratch] 25. Functions: a powerful tool to improve the efficiency of code writing
[Learn python from scratch] 24. String operations and traversal methods in Python
[Learn python from scratch] 23. Sets in Python (set ) and common operations
[Learn python from scratch] 22. Addition, deletion, modification, and query of dictionary in Python
[Learn python from scratch] 21. Tuples and dictionaries in Python
[Learn python from scratch] 20. Python list operation skills and examples
[Learn python from scratch] 19. Applications of looping through lists and list nesting
[Learn python from scratch] 18. Detailed explanation of the basic operations of Python lists (1)
[Learn python from scratch] 17. Python characters String format method (2)
[Learn python from scratch] 16. Python string format method (1)
[Learn python from scratch] 15. In-depth understanding of string and character set encoding
[Learn python from scratch] 14. Python characters Common operations on strings (2)
[Learn python from scratch] 13. Common operations on Python strings (1)
[Learn python from scratch] 12. Python string operations and applications
[Learn python from scratch] 11. Python loop statements and control flow
[Learn python from scratch] 10. Detailed explanation of Python conditional statements and if nesting
[Learn python from scratch] 09. Conditional judgment statements in Python
[Learn python from scratch] 08. Python understands bitwise operators and operator precedence
[Learn python from scratch] Learn python from scratch】07. Detailed explanation of Python operators: assignment, comparison and logical operators
【learn python from scratch】06. Use arithmetic operators in Python for calculations and string concatenation
【learn python from scratch】05. Output in Python and input
[Learn python from scratch] 04. Basics of Python programming: variables, data types and identifiers
[Learn python from scratch] 03. Detailed explanation of Python interactive programming and annotations
[Learn python from scratch] 02. Introduction to development tools
[Learn python from scratch] Learning python】01. Install and configure python

Guess you like

Origin blog.csdn.net/qq_33681891/article/details/133850787