Contents
How to send email from command line using SSH?
First you need to be able to send mail from the command line. There are other questions about this. On a mail server it’s probably easiest to install mailx (which is probably already installed anyway). Then you need an executable script file login-notify.sh (I put it in /etc/ssh/ for example) with the following content.
How do I set up email alert when ssh login is successful?
It uses Mailgun to send the emails so you are spared any issues with setting up STMP. You just need a Mailgun API key and a sending domain. Upon SSH login, the script will send details of the login (user, hostname, IP address, and all current environment variables) to an email address.
What’s the best way to set up SSH?
A better solution is to automate adding keys, store passwords, and to specify which key to use when accessing certain servers. Enter SSH config, which is a per-user configuration file for SSH communication. Create a new file: ~/.ssh/config and open it for editing:
How to create a SSH config file per user?
SSH config. Enter SSH config, which is a per-user configuration file for SSH communication. Create a new file: ~/.ssh/config and open it for editing: nano ~/.ssh/config Managing Custom Named SSH key. The first thing we are going to solve using this config file is to avoid having to add custom-named SSH keys using ssh-add.
How to enable ssh login notifications by email in CentOS 8?
In this tutorial, we learned how to enable notification in CentOS 8, when a user is accessing your Centos 8 Server over the SSH. It will send an email when the user accesses the system (Date and Time), and the IP address of the System from where the user accesses the system.
How does Pam work with a ssh login?
For those of you in need of an explanation of what PAM is and how it works, here is a very good one. /etc/profile is executed at every login (for bash shell users). The if statement will only return true if the user has logged in via ssh, which in turn will cause the indented code block to be run.