Get a text when someone logs into your server

Yes. Homing Pigeon (homingpigeon.dev) lets a short script text your phone on every SSH login, with the user name and the address it came from, so a login you did not expect reaches you right away. Your coding agent can set it up on the server you already have.

What to tell your agent

Use Homing Pigeon to text me the user name and IP address whenever someone logs into this server over SSH.

Your agent asks for your number, you read back the six-digit code, and it does the rest.

How it works in code

Install the command with sudo npm install -g homingpigeondev and verify your phone as root, as the notes below explain. Then save this as ssh-login-text.sh:

#!/bin/sh
[ "$PAM_TYPE" = "open_session" ] || exit 0

export PATH=/usr/local/bin:/usr/bin:/bin
export HOME=/root
host=$(hostname -s)
from=${PAM_RHOST:-an unknown address}

homingpigeon send "SSH login on $host: $PAM_USER from $from." \
  --idempotency-key "ssh-$host-$PAM_USER-$PAM_RHOST-$(date +%Y%m%d%H%M)" > /dev/null 2>&1 &
exit 0

Keep a second SSH session open while you do this, so a mistake in the PAM file cannot lock you out. Then install the script and add it to sshd's PAM file:

sudo install -m 700 ssh-login-text.sh /usr/local/sbin/ssh-login-text.sh
echo 'session optional pam_exec.so /usr/local/sbin/ssh-login-text.sh' | sudo tee -a /etc/pam.d/sshd

Good to know

  • Test it by logging in from a new terminal, with the other session still open. If the new login fails, delete the line you added to /etc/pam.d/sshd from the session you kept. sshd reads that file on every login, so there is nothing to restart.
  • The text reads like "SSH login on web-1: deploy from 203.0.113.7." pam_exec gives the script the user name in PAM_USER and the address the connection came from in PAM_RHOST.
  • The send runs in the background and the script exits right away, so a login never waits on the text, and a text that cannot be sent never stops a login. optional in the PAM line keeps the script's result from deciding whether the login succeeds.
  • pam_exec runs the script at logout too. The first line skips that, so you get one text per login.
  • Logins with a key count too, because sshd runs the session step for every login when PAM is on. Run sudo sshd -T | grep usepam to check that it says usepam yes. Only SSH logins text you. Console logins and su use other PAM files.
  • pam_exec runs the script as root with almost no environment, so the script sets PATH and HOME itself. Verify as root so the key is saved where the script looks: run sudo -i, then homingpigeon verify +15551234567, then again with the six-digit code it texts you. If which homingpigeon shows a folder other than /usr/local/bin or /usr/bin there, add it to the PATH line.
  • scp, sftp, rsync, git over SSH and tools like Ansible log in too, and each login uses one of your texts. The user, address and minute in the idempotency key mean a burst of connections from one place texts you once a minute, not once per connection. To skip an account that runs scheduled jobs, add a line such as [ "$PAM_USER" = "backup" ] && exit 0 after the first one.
  • Treat the text as a heads-up and not as your security log. Someone who gets root on the server can remove the script, and last and your system logs still hold the full record.
  • Messages are limited to 480 characters and go only to the US mobile number you verified. Delivery is not guaranteed, so treat each text as a heads-up.

Get started

Add Homing Pigeon to Claude Code, then ask for what you want:

claude mcp add homingpigeondev -- npx -y homingpigeondev mcp

You get 50 free texts every month, on US mobile numbers. See more use cases.