Linux服务器用户登录邮件告警

1,首先安装mailx工具用于发送邮件
yum -y install mailx

2,配置 mailx
vim /etc/mail.rc

#This is the configuration file for Heirloom mailx (formerly
#known under the name "nail".
#See mailx(1) for further options.
#This file is not overwritten when ‘make install‘ is run in
#the mailx build process again.

#Sccsid @(#)nail.rc 2.11 (gritter) 8/2/08

#Do not forward to mbox by default since this is likely to be
#irritating for most users today.
set hold

#Append rather than prepend when writing to mbox automatically.
#This has no effect unless ‘hold‘ is unset again.
set append

#Ask for a message subject.
set ask

#Assume a CRT-like terminal and invoke a pager.
set crt

#Messages may be terminated by a dot.
set dot

#Do not remove empty mail folders in the spool directory.
#This may be relevant for privacy since other users could
#otherwise create them with different permissions.
set keep

#Do not remove empty private mail folders.
set emptybox

#Quote the original message in replies by "> " as usual on the Internet.
set indentprefix="> "

#Automatically quote the text of the message that is responded to.
set quote

#Outgoing messages are sent in ISO-8859-1 if all their characters are
#representable in it, otherwise in UTF-8.
set sendcharsets=iso-8859-1,utf-8

#Display sender‘s real names in header summaries.
set showname

#Display the recipients of messages sent by the user himself in
#header summaries.
set showto

#Automatically check for new messages at each prompt, but avoid polling
#of IMAP servers or maildir folders.
set newmail=nopoll

#If threaded mode is activated, automatically collapse thread.
set autocollapse

#Mark messages that have been answered.
set markanswered

#Hide some header fields which are uninteresting for most human readers.
ignore received in-reply-to message-id references
ignore mime-version content-transfer-encoding

#Only include selected header fields when forwarding messages.
fwdretain subject date from to

#For Linux and BSD, this should be set.
set bsdcompat

set from=15172587091@163.com
set smtp="smtps://smtp.163.com:465"
set smtp-auth-user=15172587091@163.com
set smtp-auth-password=qincexxx
set smtp-auth=login
set nss-config-dir=/etc/pki/nssdb/mail/

3,测试mailx工具是否可以正常发送邮件
echo "test 123456"|mail -v -s "title" 1455373819@qq.com

4,写入用户家目录下的环境变量文件中,这里测试的root用户
vim /root/.bashrc

if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
echo "$(whoami) login at: $(date) ip address: $(w|sed -n ‘3p‘|awk ‘{print$3}‘)" | mail -s root 1455373819@qq.com

5,使配置配置文件生效并退出shell终端进行测试
source /root/.bashrc

6,重新登录测试

原文地址:https://blog.51cto.com/13718210/2361192

时间: 2024-08-06 03:20:52

Linux服务器用户登录邮件告警的相关文章

linux服务器登录邮件告警python程序

linux服务器用户登录邮件告警python小程序,一旦有人登录服务器就发邮件通知系统管理员.作为SA有些服务器只有自己可以登录的,你懂的!可有时候会被研发坑,被运维坑.为了全面掌控服务器,配置一个用户登录系统邮件通知,是很必要滴! 比较渣渣的一个脚本,不过在次基础上可以很容易的扩展滴.直接上代码了. #!/usr/bin/python#coding:utf8import smtplibimport stringimport psutilimport datetime HOST = "smtp.

Linux 服务器和Windows服务器 用户登录失败次数限制【互联网金融系统漏洞排查】

1.Linux服务器用户登录失败次数限制(使用pam模块实现) /etc/pam.d/sshd    (远程ssh) /etc/pam.d/login    (终端) 1.1.用户通过ssh登录失败次数的限制 第一步)需要使用pam模块来实现此功能,检查是否有pam_tally2.so文件 # find /lib* -name pam_tally2.so /lib64/security/pam_tally2.so 第二步)修改配置文件: # vi /etc/pam.d/sshd #%PAM-1.

linux服务器用户管理

用户管理 线上服务器不同的用户负责不同的部分,比如架构工程师需要web相关权限,DBA需要数据库相关的权限.协调好可用性以及安全性,如何管理? 我采用的是普通用户权限+sudoer+facl+group+应用账号 web维护人员: 系统普通账号+tomcat配置复杂密码后禁用远程登录,    (参考:http://blog.csdn.net/linghe301/article/details/8211305) 这里提到ssh配置文件的DenyUsers 很好用.可方便管理tomcat相关数据和服

Linux服务器 上登录MySql

Linux服务器 上登录MySql  : 1.mysql -uroot -p123 这样只指定用户,而不指定主机,这样默认以localhost登录. 2.mysql -hlocalhost -uroot -p -h数据库主机 -u用户 -p密码 -P端口号(大写P) 例如mysql -hlocalhost -uroot -p12345 -P3306 -p密码部分,可以直接指定密码,如果不指定,会提示输入密码. 我们先mysql -hlocalhost -uroot -p看看 是不是提示输入密码?

实时监控Linux服务器用户操作命令

在/etc/profile 追加 export HISTORY_FILE=/var/log/history/userhistory.log readonly PROMPT_COMMAND='{ date "+%y-%m-%d %T ##### $(who am i |awk "{print \$1\" \"\$2\" \"\$NF}")  #### $(id|awk "{print \$1}") #### $(his

通过登入IP记录Linux所有用户登录所操作的日志

通过登入IP记录Linux所有用户登录所操作的日志 对于Linux用户操作记录一般通过命令history来查看历史记录,但是如果在由于误操作而删除了重要的数据的情况下,history命令就不会有什么作用了.那么依然要存有历史操作记录应该如何来实现呢?其实我们可以通过登陆IP地址来记录所有用户登录所操作的历史操作!具体操作就是在/etc/profile配置文件的末尾加入以下脚本代码来实现: # History USER=`whoami` USER_IP=`who -u am i 2>/dev/nu

linux PAM 用户登录认证

PAM(Pluggable Authentication Modules )是由Sun提出的一种认证机制.它通过提供一些动态链接库和一套统一的API,将系统提供的服务 和该服务的认证方式分开,使得系统管理员可以灵活地根据需要给不同的服务配置不同的认证方式而无需更改服务程序,同时也便于向系 统中添加新的认证手段.从本篇开始会总结一些常用的pam模块及其实现的功能,今天讲的是pam_tally2模块. 一.参数与场景 应用场景:设置Linux用户连续N次输入错误密码进行登陆时,自动锁定X分钟或永久锁

阿里云CentOS Linux服务器上搭建邮件服务器遇到的问题

参考文章: 阿里云CentOS Linux服务器上用postfix搭建邮件服务器 Linux系统下邮件服务器的搭建(Postfix+Dovecot) 本来想自己搭建邮件服务器,但是看到一篇资料表示阿里云为了禁止垃圾邮件,禁用了25端口. 可以使用阿里云的邮件推送服务. SMTP之PHP调用示例 email.class.php下载

linux服务器发送报警邮件

由于公司业务需要,领导要求发送报警邮件,在我的认知中应该是有两种,一种是将服务器搭建为邮件服务器,这种可以使用postfix或者sendmail等,但是配置相对比较复杂,对运维人员水平要求也比较高.其实完全没有必要这么做.这就说到我们的第二种方法了,可以调用第三方邮件服务器.我们公司有自己的邮件服务器,所以直接新建了个账户,然后在这台需要发送的服务器上进行配置就可以了.服务器是centos6.8的系统.配置是在/etc/mail.rc这个文件中配置的.主要有以下几个配置项需要调整 [[email