2023-11-10 20:13:49 +01:00
<!doctype html>
< html lang = "en" >
< head >
< meta charset = "UTF-8" / >
< meta name = "viewport" content = "width=device-width, initial-scale=1" / >
< link href = "/css/style.css" rel = "stylesheet" / >
< title > Hardening Level Pro: Notify on SSH Login< / title >
< meta property = "og:title" content = "Hardening Level Pro: Notify on SSH Login" / >
2023-11-10 20:29:40 +01:00
< meta property = "og:description" content = "You ever anxious about somebody possibly gaining access to your machine? Fret not, you can just make it so that on any kind of login to your system directly you can get a notification on your phone." / >
2023-11-10 20:13:49 +01:00
< meta property = "og:type" content = "article" / >
< meta property = "og:url" content = "https://cronyakatsuki.xyz/blog/hardening-level-pro-notify-on-ssh-login/" / > < meta property = "article:section" content = "blog" / >
< meta property = "article:published_time" content = "2023-11-10T19:27:27+01:00" / >
< meta property = "article:modified_time" content = "2023-11-10T19:27:27+01:00" / > < meta property = "og:site_name" content = "Crony Akatsuki's Website" / >
2023-12-09 19:59:23 +01:00
2023-11-10 20:13:49 +01:00
< / head >
< body >
< header >
< h1 > Crony Akatsuki< / h1 >
< nav >
< span > < a href = "/" > Home< / a > < / span >
< span > |< / span >
< span > < a href = "/about" > About< / a > < / span >
< span > |< / span >
< span > < a href = "/blog" > Blog< / a > < / span >
< span > |< / span >
< span > < a href = "/services" > Services< / a > < / span >
< / nav >
< / header >
< main >
< div id = "content" >
< h1 > Hardening Level Pro: Notify on SSH Login< / h1 >
< div id = "blog-meta" >
< p id = "date" > 10-11-2023< / p >
< hr >
< / div >
< p > You ever anxious about somebody possibly gaining access to your machine? Fret not, you can just make it so that on any kind of login to your system directly you can get a notification on your phone.< / p >
< p > For this you will need a way to receive the messaggess. I personally use a selfhosted < a href = "https://ntfy.sh/" > ntfy.sh< / a > server.< / p >
< p > The most important way of managing your linux vps or in general any machine for most of us is ssh. So why not just get a notification whenever somebody logins!? Even you!< / p >
< p > To achieve this you will need to make a shell script and use a pam module, yes you will need to enable UsePAM in your sshd config, but don’ t worry it’ s secure.< / p >
< blockquote >
< p > /usr/bin/ntfy-ssh-login.sh< / p >
< / blockquote >
< div class = "highlight" > < pre tabindex = "0" style = "color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;" > < code class = "language-bash" data-lang = "bash" > < span style = "display:flex;" > < span > < span style = "color:#737994;font-style:italic" > #!/bin/bash
< / span > < / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#737994;font-style:italic" > < / span > < span style = "color:#ca9ee6" > if< / span > < span style = "color:#99d1db;font-weight:bold" > [< / span > < span style = "color:#a6d189" > " < / span > < span style = "color:#a6d189" > ${< / span > < span style = "color:#f2d5cf" > PAM_TYPE< / span > < span style = "color:#a6d189" > }< / span > < span style = "color:#a6d189" > " < / span > < span style = "color:#99d1db;font-weight:bold" > =< / span > < span style = "color:#a6d189" > " open_session" < / span > < span style = "color:#99d1db;font-weight:bold" > ]< / span > ; < span style = "color:#ca9ee6" > then< / span >
< / span > < / span > < span style = "display:flex;" > < span > curl < span style = "color:#8caaee" > \
< / span > < / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#8caaee" > < / span > -H prio:high < span style = "color:#8caaee" > \
< / span > < / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#8caaee" > < / span > -H tags:warning < span style = "color:#8caaee" > \
< / span > < / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#8caaee" > < / span > -d < span style = "color:#a6d189" > " SSH login: < / span > < span style = "color:#a6d189" > ${< / span > < span style = "color:#f2d5cf" > PAM_USER< / span > < span style = "color:#a6d189" > }< / span > < span style = "color:#a6d189" > from < / span > < span style = "color:#a6d189" > ${< / span > < span style = "color:#f2d5cf" > PAM_RHOST< / span > < span style = "color:#a6d189" > }< / span > < span style = "color:#a6d189" > " < / span > < span style = "color:#8caaee" > \
< / span > < / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#8caaee" > < / span > ntfy.sh/< span style = "color:#99d1db;font-weight:bold" > {< / span > YourTopic< span style = "color:#99d1db;font-weight:bold" > }< / span >
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#ca9ee6" > fi< / span >
< / span > < / span > < / code > < / pre > < / div > < blockquote >
< p > /etc/pam.d/sshd< / p >
< / blockquote >
< pre tabindex = "0" > < code class = "language-conf" data-lang = "conf" > # at the end of the file
session optional pam_exec.so /usr/bin/ntfy-ssh-login.sh
< / code > < / pre > < p > Also make sure that pam is realoaded using this command < code > pam-auth-update --force --package< / code > .< / p >
2023-11-10 20:31:25 +01:00
< p > You can modify the script to do email or anything else, but I prefer ntfy since the notification are instant.< / p >
2023-11-10 20:29:40 +01:00
< p > Hope this was of help and let’ s see you in another post.< / p > < / div >
2023-11-10 20:13:49 +01:00
< / main >
< footer >
< div id = "links" >
< span > < a href = "https://code.cronyakatsuki.xyz" > Code< / a > < / span >
< span > |< / span >
< span > < a href = "https://steamcommunity.com/id/CronyAkatsuki/" > Steam< / a > < / span >
< span > |< / span >
< span > < a href = "https://osu.ppy.sh/users/18953565" > Osu!< / a > < / span >
< span > |< / span >
< span > < a href = "https://anilist.co/user/CronyAkatsuki/" > Anilist< / a > < / span >
< span > |< / span >
< span > < a href = "https://youtube.com/channel/UClFdlNlUipHG5Kit8GbFz5Q" > Gaming Channel< / a > < / span >
< span > |< / span >
< span > < a href = "https://uptime.cronyakatsuki.xyz/status/public" > Services Status< / a > < / span >
2023-12-17 11:17:57 +01:00
< span > |< / span >
< span > < a href = "https://lemmy.cronyakatsuki.xyz/u/crony" > Lemmy< / a > < / span >
2023-11-10 20:13:49 +01:00
< / div >
< div id = "banners" >
< a rel = "noreferrer" href = "/" target = "_blank" > < img src = "/88x31.png"
alt="Me" title="Me" />< / a >
< a rel = "noreferrer" href = "https://kernel.org" target = "_blank" > < img src = "https://cyber.dabamos.de/88x31/linux_powered.gif"
alt="linux kernel" title="Best kernel in the world" />< / a >
< a rel = "noreferrer" href = "https://debian.org" target = "_blank" > < img src = "https://cyber.dabamos.de/88x31/debian.gif"
alt="debian" title="This website run's on debian" />< / a >
< a rel = "noreferrer" href = "https://bitwarden.com" target = "_blank" > < img src = "https://cyber.dabamos.de/88x31/bitwarden.gif"
alt="Bitwarden" title="Bitwarden/Vaultwarden for the win" />< / a >
< a rel = "noreferrer" target = "_blank" > < img src = "https://cyber.dabamos.de/88x31/free.gif"
alt="foss" title="Foss is the way" />< / a >
< a rel = "noreferrer" href = "https://neovim.io" target = "_blank" > < img src = "/assets/badges/neovim.gif"
alt="Neovim" title="Written in neovim" />< / a >
< a rel = "noreferrer" href = "https://landchad.net" target = "_blank" > < img src = "https://landchad.net/pix/landchad.gif"
alt="LandChad" title="Get A Website!" />< / a >
< a rel = "noreferrer" href = "https://poggerer.xyz" target = "_blank" > < img src = "https://poggerer.xyz/88x31.png"
alt="Tulg" title="Tulg" />< / a >
< a rel = "noreferrer" href = "https://arthurmelton.com" target = "_blank" > < img src = "https://arthurmelton.com/88x31.png"
alt="AMTitan" title="AMTitan" />< / a >
< a rel = "noreferrer" href = "https://aadi.net.in" target = "_blank" > < img src = "https://aadi.net.in/88x31.png"
alt="Aadi" title="Aadi" />< / a >
< a rel = "noreferrer" href = "https://bear.oops.wtf/" target = "_blank" > < img src = "https://bear.oops.wtf/download/88x31.png"
alt="Bear" title="Bear" />< / a >
< / div >
< / footer >
< / body >
< / html >