Send mail on login for a host











up vote
0
down vote

favorite












Is there any way to send a custom e-mail to custom recipients if any user tries to login or login to my system (RHEL6.7) ??










share|improve this question
























  • fail2ban is a brute force detection systems and can be configured to send emails on failed login attempts.
    – Raman Sailopal
    Sep 12 '17 at 14:11










  • @RamanSailopal She would also like to have an email sent on successful login attempts, it seems.
    – Kusalananda
    Sep 12 '17 at 14:12










  • If a slight delay/digest mode is OK, then logwatch may do what you want - simply monitor the auth.log
    – ivanivan
    Sep 12 '17 at 14:54










  • @ivanivan little delay is Ok thanks for the response but how to use logwatch is it a package? how to setup the same? also at the same time setting this up will have any effect on the System space? just asking as it will generate logs too i guess
    – Rebbeca
    Sep 12 '17 at 15:08

















up vote
0
down vote

favorite












Is there any way to send a custom e-mail to custom recipients if any user tries to login or login to my system (RHEL6.7) ??










share|improve this question
























  • fail2ban is a brute force detection systems and can be configured to send emails on failed login attempts.
    – Raman Sailopal
    Sep 12 '17 at 14:11










  • @RamanSailopal She would also like to have an email sent on successful login attempts, it seems.
    – Kusalananda
    Sep 12 '17 at 14:12










  • If a slight delay/digest mode is OK, then logwatch may do what you want - simply monitor the auth.log
    – ivanivan
    Sep 12 '17 at 14:54










  • @ivanivan little delay is Ok thanks for the response but how to use logwatch is it a package? how to setup the same? also at the same time setting this up will have any effect on the System space? just asking as it will generate logs too i guess
    – Rebbeca
    Sep 12 '17 at 15:08















up vote
0
down vote

favorite









up vote
0
down vote

favorite











Is there any way to send a custom e-mail to custom recipients if any user tries to login or login to my system (RHEL6.7) ??










share|improve this question















Is there any way to send a custom e-mail to custom recipients if any user tries to login or login to my system (RHEL6.7) ??







linux shell scripting rhel email






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 at 20:00









Rui F Ribeiro

38.3k1475126




38.3k1475126










asked Sep 12 '17 at 14:00









Rebbeca

276




276












  • fail2ban is a brute force detection systems and can be configured to send emails on failed login attempts.
    – Raman Sailopal
    Sep 12 '17 at 14:11










  • @RamanSailopal She would also like to have an email sent on successful login attempts, it seems.
    – Kusalananda
    Sep 12 '17 at 14:12










  • If a slight delay/digest mode is OK, then logwatch may do what you want - simply monitor the auth.log
    – ivanivan
    Sep 12 '17 at 14:54










  • @ivanivan little delay is Ok thanks for the response but how to use logwatch is it a package? how to setup the same? also at the same time setting this up will have any effect on the System space? just asking as it will generate logs too i guess
    – Rebbeca
    Sep 12 '17 at 15:08




















  • fail2ban is a brute force detection systems and can be configured to send emails on failed login attempts.
    – Raman Sailopal
    Sep 12 '17 at 14:11










  • @RamanSailopal She would also like to have an email sent on successful login attempts, it seems.
    – Kusalananda
    Sep 12 '17 at 14:12










  • If a slight delay/digest mode is OK, then logwatch may do what you want - simply monitor the auth.log
    – ivanivan
    Sep 12 '17 at 14:54










  • @ivanivan little delay is Ok thanks for the response but how to use logwatch is it a package? how to setup the same? also at the same time setting this up will have any effect on the System space? just asking as it will generate logs too i guess
    – Rebbeca
    Sep 12 '17 at 15:08


















fail2ban is a brute force detection systems and can be configured to send emails on failed login attempts.
– Raman Sailopal
Sep 12 '17 at 14:11




fail2ban is a brute force detection systems and can be configured to send emails on failed login attempts.
– Raman Sailopal
Sep 12 '17 at 14:11












@RamanSailopal She would also like to have an email sent on successful login attempts, it seems.
– Kusalananda
Sep 12 '17 at 14:12




@RamanSailopal She would also like to have an email sent on successful login attempts, it seems.
– Kusalananda
Sep 12 '17 at 14:12












If a slight delay/digest mode is OK, then logwatch may do what you want - simply monitor the auth.log
– ivanivan
Sep 12 '17 at 14:54




If a slight delay/digest mode is OK, then logwatch may do what you want - simply monitor the auth.log
– ivanivan
Sep 12 '17 at 14:54












@ivanivan little delay is Ok thanks for the response but how to use logwatch is it a package? how to setup the same? also at the same time setting this up will have any effect on the System space? just asking as it will generate logs too i guess
– Rebbeca
Sep 12 '17 at 15:08






@ivanivan little delay is Ok thanks for the response but how to use logwatch is it a package? how to setup the same? also at the same time setting this up will have any effect on the System space? just asking as it will generate logs too i guess
– Rebbeca
Sep 12 '17 at 15:08












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










There are multiple ways to achieve what you are looking for. I will list out two ways to do it.





  1. logwatch, a log-monitoring system that can send emails reporting any ssh activity.



    sudo yum install logwatch 
    sudo cp /usr/share/logwatch/default.conf/logwatch.conf /etc/logwatch/conf/logwatch.conf
    sudo logwatch --service sshd --range today --mailto <custom email IDs of recipients comma separated> --detail low



  2. A custom shell script in the /etc/profile.d folder. Normally, this script will be executed each time any user logs in the system.



    You may copy the following script into /etc/profile.d/name_of_the_alerts_file.sh file. It will send an email with the text produced by the echo. The whoami will be replaced by the current user and the hostname by the server's name.



    #!/bin/bash 
    echo -e "
    ########################################################
    # This is an alert you requested for
    # User `whoami` logged into `hostname` at `date`
    #
    #
    ########################################################
    " | mailx -r login-alerts -s "Login-Alert on `hostname`" <recipient 1>,<recipient 2>



The second method is useful if you want to customize the message being sent in the emails.






share|improve this answer























  • There is Linux-Mag article describing how to use logwatch. It includes an example using it to monitor sshd activity.
    – Jaime
    Sep 18 '17 at 5:09










  • @Pradeep Ravilla - Super usefull :-) heads up for the detailed solution
    – Rebbeca
    Sep 18 '17 at 14:13











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f391811%2fsend-mail-on-login-for-a-host%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










There are multiple ways to achieve what you are looking for. I will list out two ways to do it.





  1. logwatch, a log-monitoring system that can send emails reporting any ssh activity.



    sudo yum install logwatch 
    sudo cp /usr/share/logwatch/default.conf/logwatch.conf /etc/logwatch/conf/logwatch.conf
    sudo logwatch --service sshd --range today --mailto <custom email IDs of recipients comma separated> --detail low



  2. A custom shell script in the /etc/profile.d folder. Normally, this script will be executed each time any user logs in the system.



    You may copy the following script into /etc/profile.d/name_of_the_alerts_file.sh file. It will send an email with the text produced by the echo. The whoami will be replaced by the current user and the hostname by the server's name.



    #!/bin/bash 
    echo -e "
    ########################################################
    # This is an alert you requested for
    # User `whoami` logged into `hostname` at `date`
    #
    #
    ########################################################
    " | mailx -r login-alerts -s "Login-Alert on `hostname`" <recipient 1>,<recipient 2>



The second method is useful if you want to customize the message being sent in the emails.






share|improve this answer























  • There is Linux-Mag article describing how to use logwatch. It includes an example using it to monitor sshd activity.
    – Jaime
    Sep 18 '17 at 5:09










  • @Pradeep Ravilla - Super usefull :-) heads up for the detailed solution
    – Rebbeca
    Sep 18 '17 at 14:13















up vote
1
down vote



accepted










There are multiple ways to achieve what you are looking for. I will list out two ways to do it.





  1. logwatch, a log-monitoring system that can send emails reporting any ssh activity.



    sudo yum install logwatch 
    sudo cp /usr/share/logwatch/default.conf/logwatch.conf /etc/logwatch/conf/logwatch.conf
    sudo logwatch --service sshd --range today --mailto <custom email IDs of recipients comma separated> --detail low



  2. A custom shell script in the /etc/profile.d folder. Normally, this script will be executed each time any user logs in the system.



    You may copy the following script into /etc/profile.d/name_of_the_alerts_file.sh file. It will send an email with the text produced by the echo. The whoami will be replaced by the current user and the hostname by the server's name.



    #!/bin/bash 
    echo -e "
    ########################################################
    # This is an alert you requested for
    # User `whoami` logged into `hostname` at `date`
    #
    #
    ########################################################
    " | mailx -r login-alerts -s "Login-Alert on `hostname`" <recipient 1>,<recipient 2>



The second method is useful if you want to customize the message being sent in the emails.






share|improve this answer























  • There is Linux-Mag article describing how to use logwatch. It includes an example using it to monitor sshd activity.
    – Jaime
    Sep 18 '17 at 5:09










  • @Pradeep Ravilla - Super usefull :-) heads up for the detailed solution
    – Rebbeca
    Sep 18 '17 at 14:13













up vote
1
down vote



accepted







up vote
1
down vote



accepted






There are multiple ways to achieve what you are looking for. I will list out two ways to do it.





  1. logwatch, a log-monitoring system that can send emails reporting any ssh activity.



    sudo yum install logwatch 
    sudo cp /usr/share/logwatch/default.conf/logwatch.conf /etc/logwatch/conf/logwatch.conf
    sudo logwatch --service sshd --range today --mailto <custom email IDs of recipients comma separated> --detail low



  2. A custom shell script in the /etc/profile.d folder. Normally, this script will be executed each time any user logs in the system.



    You may copy the following script into /etc/profile.d/name_of_the_alerts_file.sh file. It will send an email with the text produced by the echo. The whoami will be replaced by the current user and the hostname by the server's name.



    #!/bin/bash 
    echo -e "
    ########################################################
    # This is an alert you requested for
    # User `whoami` logged into `hostname` at `date`
    #
    #
    ########################################################
    " | mailx -r login-alerts -s "Login-Alert on `hostname`" <recipient 1>,<recipient 2>



The second method is useful if you want to customize the message being sent in the emails.






share|improve this answer














There are multiple ways to achieve what you are looking for. I will list out two ways to do it.





  1. logwatch, a log-monitoring system that can send emails reporting any ssh activity.



    sudo yum install logwatch 
    sudo cp /usr/share/logwatch/default.conf/logwatch.conf /etc/logwatch/conf/logwatch.conf
    sudo logwatch --service sshd --range today --mailto <custom email IDs of recipients comma separated> --detail low



  2. A custom shell script in the /etc/profile.d folder. Normally, this script will be executed each time any user logs in the system.



    You may copy the following script into /etc/profile.d/name_of_the_alerts_file.sh file. It will send an email with the text produced by the echo. The whoami will be replaced by the current user and the hostname by the server's name.



    #!/bin/bash 
    echo -e "
    ########################################################
    # This is an alert you requested for
    # User `whoami` logged into `hostname` at `date`
    #
    #
    ########################################################
    " | mailx -r login-alerts -s "Login-Alert on `hostname`" <recipient 1>,<recipient 2>



The second method is useful if you want to customize the message being sent in the emails.







share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 18 '17 at 5:08









Jaime

25115




25115










answered Sep 18 '17 at 2:15









Pradeep Ravilla

362




362












  • There is Linux-Mag article describing how to use logwatch. It includes an example using it to monitor sshd activity.
    – Jaime
    Sep 18 '17 at 5:09










  • @Pradeep Ravilla - Super usefull :-) heads up for the detailed solution
    – Rebbeca
    Sep 18 '17 at 14:13


















  • There is Linux-Mag article describing how to use logwatch. It includes an example using it to monitor sshd activity.
    – Jaime
    Sep 18 '17 at 5:09










  • @Pradeep Ravilla - Super usefull :-) heads up for the detailed solution
    – Rebbeca
    Sep 18 '17 at 14:13
















There is Linux-Mag article describing how to use logwatch. It includes an example using it to monitor sshd activity.
– Jaime
Sep 18 '17 at 5:09




There is Linux-Mag article describing how to use logwatch. It includes an example using it to monitor sshd activity.
– Jaime
Sep 18 '17 at 5:09












@Pradeep Ravilla - Super usefull :-) heads up for the detailed solution
– Rebbeca
Sep 18 '17 at 14:13




@Pradeep Ravilla - Super usefull :-) heads up for the detailed solution
– Rebbeca
Sep 18 '17 at 14:13


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f391811%2fsend-mail-on-login-for-a-host%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

サソリ

広島県道265号伴広島線

Accessing regular linux commands in Huawei's Dopra Linux