Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
58
rated 0 times [  58] [ 0]  / answers: 1 / hits: 128716  / 2 Years ago, mon, october 17, 2022, 5:48:37

Does anyone have a bash script that will email or notify someone in the case of a successful login to a ssh server? I want to be notified if anyone logs into my personal box.



I'm using Ubuntu 12.04 running xfce


More From » bash

 Answers
6

Warning: according to the comments, this does not work if the user creates a file called ~/.ssh/rc.*




Modify or create /etc/ssh/sshrc with the following contents:



ip=`echo $SSH_CONNECTION | cut -d " " -f 1`

logger -t ssh-wrapper $USER login from $ip
echo "User $USER just logged in from $ip" | sendemail -q -u "SSH Login" -f "Originator <[email protected]>" -t "Your Name <[email protected]>" -s smtp.server.com &





This will effectively notify you by email anytime someone logs in through SSH, and the login will be logged in the syslog.



Note: You'll need the sendemailpackage (sudo apt-get install sendemail) for the email notification to work.



Note: works with port forwarding, but with -N option not.


[#35964] Tuesday, October 18, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ncharm

Total Points: 255
Total Questions: 105
Total Answers: 118

Location: Virgin Islands (U.S.)
Member since Sat, May 6, 2023
1 Year ago
ncharm questions
;