| View previous topic :: View next topic |
| Author |
Message |
F4lC0N n00b

Joined: 03 Jan 2004 Posts: 20
|
Posted: Mon Jun 27, 2005 6:10 pm Post subject: Email notification when user logs on via ssh |
|
|
Ive searched and searched but cant find out how to get an email sent whenever some one logs on via ssh
so what i want is something that sends an email to say monitor@domain.com every time a user logs on.
can any one give me a few pointers or a solution ? im not a good programer so writing a script that goes threw the logs isnt an option. |
|
| Back to top |
|
 |
echto Tux's lil' helper


Joined: 30 Jun 2002 Posts: 106
|
Posted: Mon Jun 27, 2005 10:13 pm Post subject: |
|
|
Quick and dirty.
tail -f /var/log/messages | grep sshd | grep opened | mail -s ssh your@emailaddr.com
 |
|
| Back to top |
|
 |
Genone Retired Dev


Joined: 14 Mar 2003 Posts: 7742 Location: beyond the rim
|
Posted: Mon Jun 27, 2005 10:54 pm Post subject: |
|
|
| I'd just hack something into /etc/profile. |
|
| Back to top |
|
 |
F4lC0N n00b

Joined: 03 Jan 2004 Posts: 20
|
Posted: Mon Jun 27, 2005 11:40 pm Post subject: |
|
|
| Genone wrote: | | I'd just hack something into /etc/profile. |
i was thinking something like that but didnt know how to do it
can you give me a pointer or two ?
i can email from the cli just getting it to send an email when some one logs in is the problem |
|
| Back to top |
|
 |
Genone Retired Dev


Joined: 14 Mar 2003 Posts: 7742 Location: beyond the rim
|
Posted: Tue Jun 28, 2005 12:31 am Post subject: |
|
|
When you're logged in with ssh it sets a few environment variables (SSH_CONNECTION, SSH_CLIENT and a few more), just test for those in a if statement in /etc/profile:
| Code: | if [ -n "$SSH_CONNECTION" ]; then
# send mail
fi
|
I've used something similar for example to restrict ssh shell access to root, but still allow cvs+ssh access to users (and no, using only keys wasn't an option).
Last edited by Genone on Tue Jun 28, 2005 3:20 am; edited 1 time in total |
|
| Back to top |
|
 |
F4lC0N n00b

Joined: 03 Jan 2004 Posts: 20
|
Posted: Tue Jun 28, 2005 12:35 am Post subject: |
|
|
that sounds pretty good
I take it theres an enviroment variable that i can insert into the email to say what the user name is ? |
|
| Back to top |
|
 |
echto Tux's lil' helper


Joined: 30 Jun 2002 Posts: 106
|
Posted: Tue Jun 28, 2005 12:36 am Post subject: |
|
|
| Genone wrote: | Why you're logged in with ssh it sets a few environment variables (SSH_CONNECTION, SSH_CLIENT and a few more), just test for those in a if statement in /etc/profile:
| Code: | if [ -n "$SSH_CONNECTION" ]; then
# send mail
fi
|
I've used something similar for example to restrict ssh shell access to root, but still allow cvs+ssh access to users (and no, using only keys wasn't an option). |
Good one!
I keep forgetting about /etc/profile.
I think I'll go walk into a fish market and yell "QUICK! Someone slap me with a wet trout!"
 |
|
| Back to top |
|
 |
F4lC0N n00b

Joined: 03 Jan 2004 Posts: 20
|
Posted: Tue Jun 28, 2005 3:16 am Post subject: |
|
|
Thanks heres what ive got
if [ -n "$SSH_CONNECTION" ]; then
echo "WARNING: user $USER has loged on " |mail -s"WARNING: user $USER has loged on " user@domain.com
fi
works like a charm
sends and email with the users name in when the ssh in and doesnt send one if the sftp in
Thanks for your help |
|
| Back to top |
|
 |
mach.82 Tux's lil' helper

Joined: 30 Oct 2003 Posts: 75 Location: 43°N/79°W
|
Posted: Mon Aug 08, 2005 10:51 pm Post subject: |
|
|
I don't have the mail command in my Gentoo system as I am using postfix!
Also, I don't think ssmtp and postfix can co-exist in the same system.
Q: What else can I use instead of the mail command with Postfix?
Thanks. |
|
| Back to top |
|
 |
zOOz n00b


Joined: 24 Sep 2003 Posts: 27 Location: Lithuania
|
Posted: Mon Aug 08, 2005 11:48 pm Post subject: |
|
|
| mach.82 wrote: | I don't have the mail command in my Gentoo system as I am using postfix!
Also, I don't think ssmtp and postfix can co-exist in the same system.
Q: What else can I use instead of the mail command with Postfix?
Thanks. |
You can use mail-client/nail it is very nice and configurable. |
|
| Back to top |
|
 |
|