概要
SSHログインが成功すると、Lineに通知が行くようにした。
前準備
- iftttで ifがWebHookなるものをつくっておく
https://ifttt.com/maker_webhooks からDocumentationでcurlのコマンドを出力させておく。
作業
vi /etc/ssh/sshrc
sshrc
curl -s -o /dev/null -X POST -H "Content-Type: application/json" -d @- https://maker.ifttt.com/trigger/イベント名/with/key/キー << EOS
{"value1":"[SSHログイン] ユーザー名: $USER, IP: $SSH_CLIENT"}
これでおk。
ただし、ここでどんな些細なことでも標準出力があると、sftpが使えなくなるので注意。
結果
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-74-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information disabled due to load higher than 8.0
* Canonical Livepatch is available for installation.
- Reduce system reboots and improve kernel security. Activate at:
https://ubuntu.com/livepatch
0 packages can be updated.
0 updates are security updates.
Last login: Sat Jan 25 15:50:56 2020 from
mirmdock@mirm_dockernode:~$
参考
https://qiita.com/tekitoh/items/8acccb313d6e7a14c2ec
https://bacchi.me/linux/ssh-login-alert/