Answer the question
In order to leave comments, you need to log in
How to run a script when trying to connect to an SSH server?
How can I configure an SSH server (OpenSSH on Linux) to run a special script when trying to connect?
If possible, it is better to pass the client's IP address as a parameter to the script.
The script should not run during normal authorization on the computer.
Answer the question
In order to leave comments, you need to log in
Put the required commands in /etc/ssh/sshrc and they will be executed after a successful login but before the shell. The client's IP address can be taken from the SSH_CONNECTION or SSH_CLIENT variable. See man sshd, section on SSHRC for details.
Please note that this will be performed with client rights.
If you need it so that the script sends login notifications via ssh, by mail, sms, or something else, then the correct option looks a little different:
The script should monitor the log for ssh login, and send notifications.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question