Terminal/SSH 欢迎信息 and 邮件登录提醒

之前逛论坛时候看到一个给ssh连接加提醒和欢迎界面的。原方法是使用的TG和微信的API来做推送,我做了一个可以通过邮件的。用Python和flask建了一个接收登录信息的服务器然后用谷歌Gmail来发邮件个别的邮箱提醒。

shell文件来源于论坛内容。我稍微修改了一些来适配邮件的部分。主要修改在最后几行。

shell文件需要修改的部分:<YOUR DEVICE NAME>: 你的设备名称,会在邮件标题里面。
root:password 你的flask网站用户名和密码
serverip:80. 你的邮件服务器ip和port

mail.py
邮件服务器文件。python
使用了flask和flask_httpauth两个库。

需要改的内容:
user = {root:password} 用户字典,可以多个,建议修改,不要使用默认账号密码

sender_address: 作为发件人的邮箱地址

sender_pass: 发件人的app password。在gmail里,点右上角的账户-> manage your google account, security password-> app password.

receiver_address: 你想收到提醒的邮箱

app.run(host=’yourip’,port = 80,debug= False) 填入主机ip和port。如果是内网ip+端口转发,请输入内网ip,shell文件输入公网ip

可以使用tmux在后台托管运行

源码

One thought on “Terminal/SSH 欢迎信息 and 邮件登录提醒

  1. My friend, you are so cool. I’m very proud of you. Although I don’t understand most of the content, I will continue to learn.
    By the way, how do I subscribe this website to receive the latest news in the first?

Leave a Reply

Your email address will not be published. Required fields are marked *