add notifications for successful ssh logins
This commit is contained in:
parent
76b6b1097c
commit
e4abf5c1ed
@ -16,4 +16,35 @@
|
||||
machines.aristotle.pubkey
|
||||
machines.phone.pubkey
|
||||
];
|
||||
|
||||
environment.etc."ssh/sshrc".text = ''
|
||||
login_ip="''${SSH_CLIENT%% *}"
|
||||
is_in_ignored=$(grep "$login_ip" /etc/ssh/ignored_ips -c)
|
||||
if [ "$is_in_ignored" -gt 0 ]; then
|
||||
echo "Your login has been ignored based on your IP address."
|
||||
exit
|
||||
fi
|
||||
time=$(date "+%T%:z")
|
||||
geodata=$(
|
||||
curl -s ipinfo.io/$login_ip |
|
||||
sed '1d;$d;/readme/d;s/^ //g'
|
||||
)
|
||||
${pkgs.mailutils}/bin/mail \
|
||||
ryan@beepboop.systems -r "ssh" \
|
||||
-s "ssh login from $login_ip at $time" \
|
||||
<<EOF
|
||||
Hi there,
|
||||
|
||||
\`netbox\` was just logged into from $login_ip at $time (America/Chicago).
|
||||
It was not in /etc/ssh/ignored_ips.
|
||||
|
||||
If this is you, that's great! If not, there is most certainly
|
||||
an unauthorized user connected to the machine -- in which case, the
|
||||
prudent course of action is to shut the machine down.
|
||||
|
||||
For your information, here is geolocation data from $login_ip.
|
||||
|
||||
$geodata
|
||||
EOF
|
||||
'';
|
||||
}
|
||||
|
@ -2,18 +2,21 @@
|
||||
{
|
||||
services.sslh = {
|
||||
enable = true;
|
||||
settings.protocols = [
|
||||
{
|
||||
host = "localhost";
|
||||
name = "ssh";
|
||||
port = "55555";
|
||||
service = "ssh";
|
||||
}
|
||||
{
|
||||
host = "localhost";
|
||||
name = "tls";
|
||||
port = "442";
|
||||
}
|
||||
];
|
||||
settings = {
|
||||
protocols = [
|
||||
{
|
||||
host = "localhost";
|
||||
name = "ssh";
|
||||
port = "55555";
|
||||
service = "ssh";
|
||||
}
|
||||
{
|
||||
host = "localhost";
|
||||
name = "tls";
|
||||
port = "442";
|
||||
}
|
||||
];
|
||||
transparent = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user