Sshd itself won't do this for you, but you could probably accomplish what you want using the pam_exec module (assuming that you've got SSH using PAM). Something like this might work (in /etc/pam.d/sshd):
session optional pam_exec.so /path/to/your/script
You could also watch /var/log/secure (or your local equivalent) for messages sshd logs when someone logs in, and trigger and email based on that.
You could also probably hack something together using the ForceCommand option in sshd. You would have ForceCommand run a script that would send the email and then use the SSH_ORIGINAL_COMMAND environment variable to run the user's shell (or whatever other command they were attempting to run). I only mention this because it might work, not because I think it's a good idea.
You could use swatch (which is designed to watch logfiles and send emails with lines matching regexps) to monitor /var/log/secure (or wherever your OS logs ssh logins), looking for lines like
sshd[xxxxx]: pam_unix(sshd:session): session opened for user foo by (uid=0)
Sshd itself won't do this for you, but you could probably accomplish what you want using the
pam_exec
module (assuming that you've got SSH usingPAM
). Something like this might work (in/etc/pam.d/sshd
):You could also watch
/var/log/secure
(or your local equivalent) for messages sshd logs when someone logs in, and trigger and email based on that.You could also probably hack something together using the
ForceCommand
option in sshd. You would haveForceCommand
run a script that would send the email and then use theSSH_ORIGINAL_COMMAND
environment variable to run the user's shell (or whatever other command they were attempting to run). I only mention this because it might work, not because I think it's a good idea.You could append this to the end of /etc/profile
This will email root with a list of logged in users everytime bash (the user's shell) is started.
You could use swatch (which is designed to watch logfiles and send emails with lines matching regexps) to monitor
/var/log/secure
(or wherever your OS logs ssh logins), looking for lines likeand sending mails accordingly.