Is production: true
#migrated

Title: How to set up pam base SSH Login Email Notification

Created: 19 Mar 2023 Modified: 19 Mar 2023

Description:



[Legacy Link]

[Link]

Instructions

  1. Install python3

    yum install -y python3 python3-pip
    
  2. Install send mail module

    #In centos or ubuntu
    pip3 install --index-url https://nexus.xethh.me/repository/pypi/simple --upgrade XSysLogSendmail
    
    #In some case in rasbian
    #pip and pip3 get messaged 
    pip3 install --index-url https://nexus.xethh.me/repository/pypi/simple --upgrade XSysLogSendmail
    
  3. Open python3 repl, send genZohoAuthenLogMail to generate a send mail script on current directory

    python3
    =========
    import XSysLogSendmail
    XSysLogSendmail.genZohoAuthenLogMail()
    
    **Current directory is /data/scripts, confirm?
    [Enter]
    **Please enter smtp host:
    [Smtp Account]
    **Please enter smtp pwd:
    [Smtp Password]
    **Please enter sender:
    [Send address]
    **Please enter receiver:
    [Receiver addresses separated by comma]
    
  4. add below line to /etc/pam.d/sshd

    #Based on the blog post, it suggest to use require
    #But to my understanding, the script maybe have change return error, which will lead to fail authen
    #So i would like to use optional instead, the operation will perceed, but result ignored
    session optional pam_exec.so {path to sh file}
    
  5. After generated the file, change modification permission

    chmod +x sendmail.sh
    
  6. Temporary disable selinux if needed, will fix this in the future [Link]

    setenforce 0
    #setenforce 1 ==> set enable