लिनक्स में PAM को कैसे कॉन्फ़िगर और उपयोग करें


लिनक्स-पीएएम (कम के लिए प्लग करने योग्य प्रमाणीकरण मॉड्यूल जो यूनिक्स-पीएएम वास्तुकला से विकसित हुआ है) साझा पुस्तकालयों का एक शक्तिशाली सूट है जो किसी उपयोगकर्ता को अनुप्रयोगों (या सेवाओं) को गतिशील रूप से प्रमाणित करने के लिए उपयोग किया जाता है ) एक लिनक्स सिस्टम में।

यह कई निम्न-स्तरीय प्रमाणीकरण मॉड्यूल को एक उच्च-स्तरीय एपीआई में एकीकृत करता है जो अनुप्रयोगों के लिए गतिशील प्रमाणीकरण समर्थन प्रदान करता है। यह डेवलपर्स को उन अनुप्रयोगों को लिखने की अनुमति देता है, जिन्हें अंतर्निहित प्रमाणीकरण प्रणाली से स्वतंत्र रूप से प्रमाणीकरण की आवश्यकता होती है।

कई आधुनिक लिनक्स वितरण लिनक्स-पीएएम का समर्थन करते हैं (बाद में डिफ़ॉल्ट रूप से " पीएएम ") के रूप में संदर्भित किया जाता है। इस लेख में, हम बताएंगे कि उन्नत PAM को Ubuntu और CentOS सिस्टम में कैसे कॉन्फ़िगर किया जाए।

इससे पहले कि हम आगे बढ़ें, ध्यान दें:

  • As a system administrator, the most important thing is to master how PAM configuration file(s) define the connection between applications (services) and the pluggable authentication modules (PAMs) that perform the actual authentication tasks. You don’t necessarily need to understand the internal working of PAM.
  • PAM has the potential to seriously alter the security of your Linux system. Erroneous configuration can disable access to your system partially, or completely. For instance an accidental deletion of a configuration file(s) under /etc/pam.d/* and/or /etc/pam.conf can lock you out of your own system!

कैसे एक कार्यक्रम की जाँच करने के लिए PAM- अवगत है

PAM को नियोजित करने के लिए, एक एप्लिकेशन/प्रोग्राम को " PAM अवगत " होना चाहिए; इसे PAM का उपयोग करने के लिए विशेष रूप से लिखा और संकलित किया जाना चाहिए। यह पता लगाने के लिए कि क्या कोई प्रोग्राम " PAM- अवगत " है या नहीं, जांचें कि क्या उसे ldd कमांड का उपयोग करके PAM लाइब्रेरी के साथ संकलित किया गया है।

उदाहरण के लिए sshd:

$ sudo ldd /usr/sbin/sshd | grep libpam.so

	libpam.so.0 => /lib/x86_64-linux-gnu/libpam.so.0 (0x00007effddbe2000)

लिनक्स में PAM को कैसे कॉन्फ़िगर करें

PAM के लिए मुख्य कॉन्फ़िगरेशन फ़ाइल /etc/pam.conf है और /etc/pam.d/ निर्देशिका में PAM कॉन्फ़िगरेशन फ़ाइलों के लिए है प्रत्येक PAM- अवगत आवेदन/सेवाएं। यदि निर्देशिका मौजूद है तो PAM फ़ाइल को अनदेखा कर देगा।

मुख्य कॉन्फ़िगरेशन फ़ाइल के लिए सिंटैक्स निम्नानुसार है। फ़ाइल एक लाइन पर लिखे नियमों की एक सूची से बनी है (आप <कोड> "\" एस्केप कैरेक्टर का उपयोग करके नियमों का विस्तार कर सकते हैं) और टिप्पणियाँ <कोड> "#" से पहले हैं निशान और लाइन के अगले छोर तक विस्तारित।

प्रत्येक नियम का प्रारूप टोकन का एक अलग-अलग संग्रह है (पहले तीन केस-असंवेदनशील हैं)। हम बाद के वर्गों में इन टोकन की व्याख्या करेंगे।

service type control-flag module module-arguments 

कहा पे:

  • service: actual application name.
  • type: module type/context/interface.
  • control-flag: indicates the behavior of the PAM-API should the module fail to succeed in its authentication task.
  • module: the absolute filename or relative pathname of the PAM.
  • module-arguments: space separated list of tokens for controlling module behavior.

/etc/pam.d/ में प्रत्येक फ़ाइल का सिंटैक्स मुख्य फ़ाइल के समान है और निम्न फ़ॉर्म की पंक्तियों से बना है:

type control-flag module module-arguments

यह /etc/pam.d/sshd फ़ाइल में पाई गई एक नियम परिभाषा (बिना मॉड्यूल-तर्कों) का एक उदाहरण है, जो /etc/nologs नॉन-रूट लॉगिन को नापसंद करता है। मजबूत> मौजूद है:

account required pam_nologin.so

पीएएम प्रबंधन समूहों और नियंत्रण-झंडे को समझना

PAM प्रमाणीकरण कार्यों को चार स्वतंत्र प्रबंधन समूहों में अलग किया जाता है। ये समूह एक विशिष्ट सेवा के लिए एक विशिष्ट उपयोगकर्ता के अनुरोध के विभिन्न पहलुओं का प्रबंधन करते हैं।

एक मॉड्यूल इन प्रबंधन समूह प्रकारों में से एक से जुड़ा है:

  • account: provide services for account verification: has the user’s password expired?; is this user permitted access to the requested service?.
  • authentication: authenticate a user and set up user credentials.
  • password: are responsible for updating user passwords and work together with authentication modules.
  • session: manage actions performed at the beginning of a session and end of a session.

PAM लोड करने योग्य ऑब्जेक्ट फ़ाइलें (मॉड्यूल) निम्नलिखित निर्देशिका में स्थित होने वाली हैं: /lib/सुरक्षा/ या /lib64/सुरक्षा वास्तुकला।

समर्थित नियंत्रण-ध्वज हैं:

  • requisite: failure instantly returns control to the application indicating the nature of the first module failure.
  • required: all these modules are required to succeed for libpam to return success to the application.
  • sufficient: given that all preceding modules have succeeded, the success of this module leads to an immediate and successful return to the application (failure of this module is ignored).
  • optional: the success or failure of this module is generally not recorded.

उपरोक्त कीवर्ड के अलावा, दो अन्य मान्य नियंत्रण झंडे हैं:

  • include: include all lines of given type from the configuration file specified as an argument to this control.
  • substack: include all lines of given type from the configuration file specified as an argument to this control.

SSH सेवा Via PAM के लिए रूट एक्सेस को कैसे प्रतिबंधित करें

एक उदाहरण के रूप में, हम SSH और लॉगिन कार्यक्रमों के माध्यम से सिस्टम में रूट उपयोगकर्ता की पहुंच को अक्षम करने के लिए PAM का उपयोग करने के लिए कॉन्फ़िगर करेंगे। यहां, हम लॉगिन और sshd सेवाओं तक पहुंच को प्रतिबंधित करके, रूट उपयोगकर्ता पहुंच को एक सिस्टम में अक्षम करना चाहते हैं।

हम /lib/security/pam_listfile.so मॉड्यूल का उपयोग कर सकते हैं जो विशिष्ट खातों के विशेषाधिकारों को सीमित करने में बहुत लचीलापन प्रदान करता है। दिखाए गए अनुसार /etc/pam.d/ निर्देशिका में लक्ष्य सेवा के लिए फ़ाइल खोलें और संपादित करें।

$ sudo vim /etc/pam.d/sshd
OR
$ sudo vim /etc/pam.d/login

इस नियम को दोनों फाइलों में जोड़ें।

auth    required       pam_listfile.so \
        onerr=succeed  item=user  sense=deny  file=/etc/ssh/deniedusers

उपरोक्त नियम में टोकन की व्याख्या:

  • auth: is the module type (or context).
  • required: is a control-flag that means if the module is used, it must pass or the overall result will be fail, regardless of the status of other modules.
  • pam_listfile.so: is a module which provides a way to deny or allow services based on an arbitrary file.
  • onerr=succeed: module argument.
  • item=user: module argument which specifies what is listed in the file and should be checked for.
  • sense=deny: module argument which specifies action to take if found in file, if the item is NOT found in the file, then the opposite action is requested.
  • file=/etc/ssh/deniedusers: module argument which specifies file containing one item per line.

अगला, हमें फ़ाइल बनाने की आवश्यकता है /etc/ssh/denusers और इसमें रूट नाम जोड़ें:

$ sudo vim /etc/ssh/deniedusers

परिवर्तन सहेजें और फ़ाइल बंद करें, फिर उस पर आवश्यक अनुमतियाँ सेट करें:

$ sudo chmod 600 /etc/ssh/deniedusers

अब से, उपरोक्त नियम पीएएम को /etc/ssh/denusers फ़ाइल से परामर्श करने और किसी भी सूचीबद्ध उपयोगकर्ता के लिए SSH और लॉगिन सेवाओं तक पहुंच से इनकार करने के लिए कहेगा।

लिनक्स में उन्नत PAM को कैसे कॉन्फ़िगर करें

अधिक जटिल PAM नियम लिखने के लिए, आप निम्न रूप में मान्य नियंत्रण-ध्वज का उपयोग कर सकते हैं:

type [value1=action1 value2=action2 …] module module-arguments

जहां valueN मॉड्यूल में लागू फ़ंक्शन से रिटर्न कोड से मेल खाती है जिसके लिए लाइन परिभाषित की गई है। आप ऑन-लाइन PAM एडमिनिस्ट्रेटर गाइड से समर्थित मान पा सकते हैं। एक विशेष मूल्य डिफ़ॉल्ट है, जिसका तात्पर्य है कि सभी मान स्पष्ट रूप से उल्लिखित नहीं हैं।

एक्शनएन निम्न रूपों में से एक ले सकता है:

  • ignore: if this action is used with a stack of modules, the module’s return status will not contribute to the return code the application obtains.
  • bad: indicates that the return code should be thought of as indicative of the module failing. If this module is the first in the stack to fail, its status value will be used for that of the whole stack.
  • die: equivalent to bad but may terminate the module stack and PAM immediately returning to the application.
  • ok: this instructs PAM that the system administrator thinks this return code should contribute directly to the return code of the full stack of modules.
  • done: equivalent to ok but may terminate the module stack and PAM immediately returning to the application.
  • N (an unsigned integer): equivalent to ok but may jump over the next N modules in the stack.
  • Reset: this action clears all memory of the state of the module stack and restart with the next stacked module.

चार खोजशब्दों में से प्रत्येक: आवश्यक; अपेक्षित; पर्याप्त; और वैकल्पिक, [...] वाक्य रचना के संदर्भ में एक समान अभिव्यक्ति है, जो आपको अधिक जटिल नियम लिखने की अनुमति देते हैं और वे हैं:

  • required: [success=ok new_authtok_reqd=ok ignore=ignore default=bad]
  • requisite: [success=ok new_authtok_reqd=ok ignore=ignore default=die]
  • sufficient: [success=done new_authtok_reqd=done default=ignore]
  • optional: [success=ok new_authtok_reqd=ok default=ignore]

निम्नलिखित एक आधुनिक CentOS 7 प्रणाली से एक उदाहरण है। आइए इन नियमों पर /etc/pam.d/postlogin PAM फ़ाइल से विचार करें:

#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
session     [success=1 default=ignore] pam_succeed_if.so service !~ gdm* service !~ su* quiet
session     [default=1]   pam_lastlog.so nowtmp showfailed
session     optional      pam_lastlog.so silent noupdate showfailed

यहाँ /etc/pam.d/smartcard-auth PAM फ़ाइल से एक और उदाहरण विन्यास है:

#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth        required      pam_env.so
auth        [success=done ignore=ignore default=die] pam_pkcs11.so nodebug wait_for_card
auth        required      pam_deny.so

account     required      pam_unix.so
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 1000 quiet
account     required      pam_permit.so

password    required      pam_pkcs11.so

session     optional      pam_keyinit.so revoke
session     required      pam_limits.so
-session     optional      pam_systemd.so
session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session     required      pam_unix.so

अधिक जानकारी के लिए, pam.d मैन पेज देखें:

$ man pam.d 

अंत में, कॉन्फ़िगरेशन फ़ाइल सिंटैक्स और सभी PAM मॉड्यूल का एक व्यापक विवरण लिनक्स-पीएएम के लिए प्रलेखन में पाया जा सकता है।

PAM एक शक्तिशाली उच्च-स्तरीय एपीआई है जो ऐसे प्रोग्राम की अनुमति देता है जो किसी लिनक्स सिस्टम में अनुप्रयोगों के लिए प्रामाणिक उपयोगकर्ताओं के प्रमाणीकरण पर भरोसा करते हैं। यह समझने और उपयोग करने के लिए शक्तिशाली लेकिन बहुत चुनौतीपूर्ण है।

इस लेख में, हमने समझाया है कि कैसे Ubuntu और CentOS में PAM की उन्नत सुविधाओं को कॉन्फ़िगर किया जाए। यदि आपके पास साझा करने के लिए कोई प्रश्न या टिप्पणी है, तो नीचे दिए गए फीडबैक फॉर्म का उपयोग करें।