{"id":158,"date":"2023-04-10T18:21:42","date_gmt":"2023-04-10T16:21:42","guid":{"rendered":"https:\/\/www.mutareb.com\/?p=158"},"modified":"2023-06-16T18:10:53","modified_gmt":"2023-06-16T16:10:53","slug":"get-an-email-notification-for-successful-ssh-logins","status":"publish","type":"post","link":"https:\/\/www.mutareb.com\/index.php\/2023\/04\/10\/get-an-email-notification-for-successful-ssh-logins\/","title":{"rendered":"Get an Email notification for successful SSH logins"},"content":{"rendered":"\n<p>This is an email alert that is triggered once a SSH login succeeds<\/p>\n\n\n\n<p>First we will create the script itself in the ssh folder \/etc\/ssh\/login-notify.sh:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/sh\n\n# Change these two lines:\nsender=\"root@serv1.example.com\"\nrecepient=\"watchdog@example.com\"\n\nif &#91; \"$PAM_TYPE\" != \"close_session\" ]; then\n    host=\"`hostname`\"\n    subject=\"SSH Login: $PAM_USER from $PAM_RHOST on $host\"\n    # Message to send, e.g. the current environment variables.\n    message=\"`env`\"\n    echo \"$message\" | mailx -r \"$sender\" -s \"$subject\" \"$recepient\"\nfi<\/code><\/pre>\n\n\n\n<p>Make the file executable, then add the following line to the end of the sshd pam file in \/etc\/pam.d\/sshd<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>session optional pam_exec.so seteuid \/etc\/ssh\/login-notify.sh<\/code><\/pre>\n\n\n\n<p>It&#8217;s set to optional for testing, as it would prevent login if the script fails, test it first before switching it to required<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is an email alert that is triggered once a SSH login succeeds First we will create the script itself in the ssh folder \/etc\/ssh\/login-notify.sh: Make the file executable, then add the following line to the end of the sshd pam file in \/etc\/pam.d\/sshd It&#8217;s set to optional for testing, as it would prevent login&hellip; <a class=\"more-link\" href=\"https:\/\/www.mutareb.com\/index.php\/2023\/04\/10\/get-an-email-notification-for-successful-ssh-logins\/\">Continue reading <span class=\"screen-reader-text\">Get an Email notification for successful SSH logins<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,17],"tags":[27,12],"series":[7],"class_list":["post-158","post","type-post","status-publish","format-standard","hentry","category-it-security","category-linux-server","tag-linux","tag-security","series-linux-server","entry"],"_links":{"self":[{"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/posts\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/comments?post=158"}],"version-history":[{"count":1,"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/posts\/158\/revisions"}],"predecessor-version":[{"id":159,"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/posts\/158\/revisions\/159"}],"wp:attachment":[{"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/media?parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/categories?post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/tags?post=158"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/series?post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}