Linux-PAM System Management Guide (1)

Source: Internet
Author: User
Article title: Linux-PAM System Management Guide (1 ). Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Abstract: Linux-PAM is a group of shared libraries. with these modules, system administrators can freely choose the verification mechanism used by applications. In other words, you do not need to recompile the application to switch the verification mechanism used by the application. The verification mechanism used by the system can be completely upgraded without touching the application.
  
1. Introduction
  
Linux-PAM (Pluggable Authentication Modules for Linux. Linux-based plug-in verification module) is a group of shared libraries. with these Modules, system administrators can freely choose the verification mechanism used by applications. In other words, you do not need to recompile the application to switch the verification mechanism used by the application. You can even upgrade the verification mechanism used by the system without touching the application.
  
Historically, applications that require user verification must be compiled together with a verification mechanism. For example, the traditional UN * X system uses passwords to verify users. The password entered by the user is encrypted by crypt and then compared with the ciphertext in the/etc/passwd file. In such a system, if priority recognition is not based on this method, the priority needs to be verified by the user identifier and user group identifier. Services and applications can be verified based on user and user group identification. Generally, user groups are allocated through the/etc/group file.
  
Unfortunately, as the computer speed increases and the network popularity increases, this authentication method becomes increasingly insecure. Therefore, many new verification methods have been developed.
  
The Linux-PAM project aims to separate the development of application software and verification mechanisms. The function library can be verified to achieve the above purpose. The PAM library is set by the local system configuration file/etc/pam. conf or some configuration files in the/etc/pam. d/directory. The module dynamically loads the target File (opened using the dloptn (3) function) and stores it in the/usr/lib/security Directory.
  
2. some instructions in this article
  
When reading this article, you should be clear about the assumption that a specific file is in a specific directory. We comply with the RFC-86's conventions. Some Linux releases place these files in different locations. Therefore, if your system is published like RedHat, you should use the example provided in this article with caution.
  
For example, if PAM can load the target File (module) in the/usr/lib/security/directory, in the RedHat Linux system, they are stored in the/lib/security Directory. Therefore, when using the example in this article, you should pay attention to the necessary conversions.
  
3. Summary
  
Let's start with an example. First, find an application that can provide services to users. login is such a program. Login needs to do two things: first query the user and then provide the user with the required services, such as providing a shell program.
  
Generally, login prompts the user to enter the password. Then verify the password. this task is completed by Linux-PAM.
  
From the programmer's perspective, the Linux-PAM task is to verify the user's legitimacy.
  
Linux-PAM has great flexibility, and system administrators can use it to freely choose a verification method. You can also choose the authentication method used by the application. Linux-PAM provides a variety of verification methods, from absolute trust (pam_permit) to retina scanning, audio analysis, and one-time password.
  
To describe the flexibility of Linux-PAM, we can assume that a system manager (parent) wants to improve the mathematical capabilities of users (their children. He/she can achieve this through the Shoot 'em up game, a child's favorite game, provided that the game can use the verification mechanism provided by PAM. Verification can be set: each time the children want to play a game, they need to answer the product of a group of random numbers less than 12. In this way, the children can practice multiplication before each game. As they grow, they can increase the size of numbers.
  
Linux-PAM processes four types of tasks: auth, account, session, and password ). The management method used by the application is set through the relevant Linux-PAM configuration file. The management function is completed by a module specified by the configuration file.
  
Application X, which calls the Linux-PAM Library through some interfaces, but does not know the verification method used. The Linux-PAM library reads the content of the PAM configuration file and loads the modules required by program X according to the configuration file. These modules enter a management group and are stacked in the order set in the configuration file. They perform various verification tasks for the application. Information exchange is implemented between applications and users through the conversation function.
  
3.1 Quick start
  
The following is a passage of Seth Chaiklin:
  
From this point of view, PAM should work in the ideal world, where all applications are not wrong. However, this is far from the case. Therefore, if you want to use PAM, consider some practical issues.
If you use Linux as a single-user system, or users in the system trust each other, it doesn't mean much to use PAM.
You can cancel PAM on a system without important things, which can bring some convenience. Make the system look like Win95.
  
In the network environment, you need to consider the issue of user authentication.
  
If you use Linux as a server and use it to provide different services, PAM will reflect its value. In general, by using different modules, the program can search for various password databases, and the program itself does not need to be rewritten. The following are some examples:
  
Apache has a module that provides the PAM service. Therefore, the Verification of a specific directory can be completed through PAM, which means that a large number of existing PAM modules can be used for verification, including RADIUS, NIS, and NCP.
Pppd has a version verified by PAM (from RedHat ).
Can I set PAM to any program that requires verification?
  
You can say either. Yes. if you can modify the source code, you can add the PAM verification function. if you cannot modify the source code, therefore, the PAM verification function cannot be added to the binary executable file sink.
  
How can I identify whether a program uses PAM verification?
  
Use the ldd command. if the dynamic connection library used by this program does not have libpam and libpam_misc, it certainly does not use PAM verification. However, the two libraries may already exist, but the program cannot work properly due to some problems. Therefore, a better method is required for testing.
For programs that require PAM, you need to set the configuration file in the/etc/pam. d Directory. The configuration file name is written into the program source code. it is usually the same as the program name, but not always. For example, there is a program called pamprog whose PAM configuration file is/etc/pam. d/pamprog. In the configuration file, there are only the following two lines: auth required pam_permit.so
Auth required pam_warn.so
  
Test it now. The first line indicates that all users are allowed to pass. The second line indicates that you want to write a warning message in syslog. If the test is successful, the program can use PAM for verification. Then you can add more complex verification functions to the configuration file.
  
4. Linux-PAM configuration file
  
Linux-PAM aims to provide system managers with maximum flexibility. The system administrator can configure Linux-PAM in two ways: a single configuration file/etc/pam. conf or the/etc/pam. d/directory. In this section, we will discuss the syntax of its configuration file.
  
4.1 configuration file syntax
  
First, you should understand that the Linux-PAM mark is case sensitive. There are two special symbols: # and. The comment in the configuration file starts with #. Generally, each line in the configuration file is an entry (except the comment). However, if the definition of an entry is too long, you can use the escape character to return to the line, the next row is also seen as part of this entry.
  
In general, each line of the/etc/pam. conf file is in this format:
  
?? Service-name module-type control-flag module-path arguments
  
Next we will explain each mark. In addition to this method, you can use the/etc/pam. d/directory to configure Linux-PAM. we will introduce this method later.
  
Service-name
The service name assigned to this portal. This is usually the session name of the given application. For example, ftpd, rlogind, and su.
  
Linux-PAM also retains a special service name (OTHER) for the default authentication mechanism, which is case sensitive. Note: If a module specifies a service named after it, OTHER will be ignored.
  
Modle-type
Linux-PAM currently has four types of modules:
  
Auth
This type of module provides two services for user authentication.
  
Ask the application to prompt the user to enter the password or other tags to confirm the validity of the user;
Use its credential permission to set the group membership (different from the/etc/groups file discussed above) or other priorities.
Account
These modules perform non-verified account management. It is mainly used to limit/allow users to access a service, the current effective system resources (up to how many users can have), and limit the user location (for example: root users can only log on from the console ).
  
Session
This type of module is mainly used to handle some things that need to be done before/after providing services to users, including recording the information for enabling/disabling data exchange and monitoring directories.
  
Password
Used to upgrade the user authentication tag.
  
Control-flag
The control flag is used to set the response that PAM needs to make after verification is successful or fails. Because the module can be stacked (stacked, the same type of modules are executed in sequence), the control mark can determine the importance of each module. The application will not realize the success or failure of a single module, but will only receive the comprehensive response information of the Linux-PAM Library's success or failure. The execution sequence of the Cascade module depends on the entry sequence of the/etc/pam. conf file. the module before the entry column is executed first. From Linux-PAM 6.0, you can use two types of syntax to define the control flag.
  
One simple way is to use a single keyword to define the control flag. There are four such keywords: required, requisite, sufficient, and optional.
  
Linux-PAM explains these keywords in the following way:
  
Required
Indicates that even if a module fails to verify the user, PAM will return an error message after all modules are executed. This is done to prevent users from knowing which module is rejected. If the user is successfully verified, all modules return the success message.
  
Requisite
If a specific module fails to verify the user, PAM immediately returns an error message, returning the control to the application, and does not execute other modules for verification.
  
Sufficient
Indicates that if a user passes the verification of this module, the PAM structure immediately returns the verification success information, and the control is applied to the application. Even if

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.