ssh登陆linux服务器

在Linux服务器上设置SSH登录后发送email提醒,可以通过以下步骤实现:

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:申请域名网站空间、营销软件、网站建设、龙陵网站维护、网站推广。

1、安装邮件发送工具

首先需要在服务器上安装一个邮件发送工具,这里以sendmail为例,在Debian/Ubuntu系统上,可以使用以下命令安装:

sudo apt-get update
sudo apt-get install sendmail

在CentOS/RHEL系统上,可以使用以下命令安装:

sudo yum install sendmail

2、配置sendmail

安装完成后,需要对sendmail进行配置,配置文件位于/etc/mail/sendmail.mc,使用文本编辑器打开配置文件,

sudo nano /etc/mail/sendmail.mc

找到以下行并进行修改:

DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

修改为:

DAEMON_OPTIONS(`Port=smtp, Name=MTA')dnl

将以下行:

dnl  Uncomment the next line to generate "delayed mail" warnings
define(confCON_EXPENSIVE', True')dnl

取消注释:

define(confCON_EXPENSIVE', True')dnl

保存并退出,接下来,使用m4编译器生成新的配置文件:

sudo m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

3、创建邮件模板

创建一个名为auth.log的文件,用于存放登录日志,文件路径可以自定义,/var/log/auth.log,使用以下命令创建文件:

sudo touch /var/log/auth.log

创建一个名为login_alert.mc的邮件模板文件,文件路径可以自定义,/etc/mail/login_alert.mc,使用以下命令创建文件:

sudo touch /etc/mail/login_alert.mc

编辑login_alert.mc文件,添加以下内容:

define(confLOGIN_MSG', $j Sending login alert for $g')dnl
define(SMTP_MAILER_ARGS', -t')dnl
FEATURE(delay_warnings)dnl
LOCAL_RULES(`$llocal_recipients')dnl
include(`smtp-generic')dnl

保存并退出,接下来,使用m4编译器生成新的邮件模板文件:

sudo m4 /etc/mail/login_alert.mc > /etc/mail/login_alert.cf

4、配置PAM(可选)

如果希望在每次用户登录时自动发送邮件提醒,可以配置PAM(可插入认证模块),安装pam_ssmtp模块:

Debian/Ubuntu系统:

sudo apt-get install libpam-ssmtp python-smtplib sasl2-bin spamassassin spamcurl unzip vim gettext-base autoconf automake libtool bison gcc make openssl libsasl2-dev libsasl2-modules-dbg libsasl2-modules:amd64 libsasl2-modules:i386 zlib1g:amd64 zlib1g:i386 libdb-dev libsqlite3-dev libmysqlclient-dev libgssglue1:amd64 libgssglue-dev:amd64 libldap2-dev libldap-common:amd64 libpcre3-dev libpcre3:amd64 libcurl4-openssl-dev libcurl4:amd64 curl:amd64 curl:i386 mailutils:amd64 mailutils:i386 mailcap:any file:any build-essential wget git rsync vim patch perl tar unzip bzip2 make automake autoconf gcc g++ binutils bison flex byacc texinfo gzip bc kmod subversion coreutils screen emacs25 ncurses-base ncurses-bin pax gperf psmisc sysvinit-utils debianutils util-linux procps cron ntpdate xz-utils zlib1g zlib1g-dev openssl openssl-blacklist ca-certificates openssl-policies tcpdump socat netcat dnsutils iproute2 iputils-ping traceroute ltrace strace sysstat iftop iotop htop screenfetch sysfsutils sysctl netcfg bind-utils avahi-daemon libnss3:amd64 libnspr4:amd64 libpam0g:amd64 libpam-modules:amd64 libpam-modules:i386 libpam-runtime:amd64 libpam0g:i386 libpam-dev:amd64 libpam-dev:i386 libsasl2-modules:amd64 libsasl2-modules:i386 libsasl2-modules-dbg:amd64 libsasl2-modules-dbg:i386 libsasl2:amd64 libsasl2:i386' && 
    wget https://github.com/amavis/amavisd/releases/download/v${AMAVISD_VERSION}/amavisd-${AMAVISD_VERSION}.tar.gz && 
    tar -xzf amavisd* && 
    cd amavisd* && 
    ./configure --with-clamav --with-sasl --with-dbdir=${DBDIR} --with-localstatedir=${STATEDIR} && 
    make && 
    make install && 
    rm -rf amavis* && 
    apt-get clean && 
    apt-get autoremove && 
    apt-get autoclean && 
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && 
    echo "deb http://www.debian.org/debian $(lsb_release -sc) main" | tee /etc/apt/sources.list && 
    echo "deb http://www.debian.org/debian $(lsb_release -sc)-updates main" | tee -a /etc/apt/sources.list && 
    echo "deb http://security.debian.org $(lsb_release -sc)-security main" | tee -a /etc/apt/sources.list && 
    echo "deb http://www.debian.org/debian $(lsb_release -sc) universe" | tee -a /etc/apt/sources.list && 
    echo "deb http://www.debian.org/debian $(lsb_release -sc) multiverse" | tee -a /etc/apt/sources.list && 
    echo "deb http://www.debian.org/debian $(lsb_release -sc)-backports main" | tee -a /etc/apt/sources.list && 
    apt update && 
    apt upgrade" && 
    apt install pam_ssmtp spamassassin spamcurl unzip vim gettext-base autoconf automake libtool bison gcc make openssl libsasl2-dev libsasl2-modules-dbg libsasl2-modules:amd64 libsasl2-modules:i386 zlib1g:amd64 zlib1g:i386 libdb-dev libsqlite3-dev libmysqlclient-dev libgssglue1:amd64 libgssglue-dev:amd64 libldap2-dev libldap-common:amd64 libpcre3-dev libpcre3:amd64 libcurl4-openssl-dev libcurl4:amd64 curl:amd64 curl:i386 mailutils:amd64 mailutils:i386 mailcap:any file:any build-essential wget git rsync vim patch perl tar unzip bzip2 make automake autoconf gcc g++ binutils bison flex byacc texinfo gzip bc kmod subversion coreutils screen emacs25 ncurses-base ncurses-bin pax gperf psmisc sysvinit-utils debianutils util-linux procp

分享文章:ssh登陆linux服务器
网页网址:http://www.shufengxianlan.com/qtweb/news47/533747.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联