新聞中心
在Linux上為SSH登錄設(shè)置電子郵件提醒

豐鎮(zhèn)網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站建設(shè)等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營(yíng)維護(hù)。成都創(chuàng)新互聯(lián)從2013年成立到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來(lái)保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)。
SSH(Secure Shell)是一種網(wǎng)絡(luò)協(xié)議,用于計(jì)算機(jī)之間的安全通信,它提供了一種加密的方式,使得遠(yuǎn)程用戶能夠安全地訪問和操作服務(wù)器,為了提高安全性,我們可以為SSH登錄設(shè)置電子郵件提醒,以便在有新的SSH登錄嘗試時(shí)及時(shí)收到通知,本文將介紹如何在Linux上為SSH登錄設(shè)置電子郵件提醒。
1、安裝郵件服務(wù)
我們需要在Linux服務(wù)器上安裝一個(gè)郵件服務(wù),有許多可用的郵件服務(wù),如Postfix、Sendmail等,這里我們以Postfix為例進(jìn)行介紹。
在Debian/Ubuntu系統(tǒng)上,可以使用以下命令安裝Postfix:
sudo apt-get update sudo apt-get install postfix
在CentOS/RHEL系統(tǒng)上,可以使用以下命令安裝Postfix:
sudo yum install postfix
安裝完成后,使用以下命令啟動(dòng)并設(shè)置為開機(jī)自啟動(dòng):
sudo systemctl start postfix sudo systemctl enable postfix
2、配置郵件服務(wù)
接下來(lái),我們需要配置郵件服務(wù),以便將其與SSH登錄提醒關(guān)聯(lián)起來(lái),編輯/etc/postfix/main.cf文件,添加以下內(nèi)容:
sender_canonical_maps = hash:/etc/postfix/sender_canonical relay_domains = your-email@example.com myhostname = your-server-hostname.example.com alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = $mydomain local_transport = error: local delivery disabled mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain relayhost = [smtp.example.com]:587 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt smtp_use_tls = yes smtpd_banner = Welcome to My SMTP server. smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $myhostname smtpd_recipient_restrictions = permit_mynetworks permit_sasl_authenticated reject_unauth_destination smtpd_sasl_security_options = noanonymous smtpd_sasl_type = dovecot smtpd_tls_cert_file = /etc/ssl/certs/your-server-cert.pem smtpd_tls_key_file = /etc/ssl/private/your-server-key.pem
請(qǐng)將your-email@example.com替換為您的電子郵件地址,將your-server-hostname.example.com替換為您的服務(wù)器主機(jī)名,將smtp.example.com替換為您的SMTP服務(wù)器地址,將your-server-cert.pem和your-server-key.pem替換為您的服務(wù)器證書和私鑰文件。
3、創(chuàng)建郵件模板
接下來(lái),我們需要?jiǎng)?chuàng)建一個(gè)郵件模板,以便在有新的SSH登錄嘗試時(shí)發(fā)送電子郵件,創(chuàng)建一個(gè)名為sshlogin.txt的文件,內(nèi)容如下:
Subject: SSH登錄嘗試 $HOSTNAME ($USER) on $DATE at $TIME from $IPADDRESS via $PROTOCOL on port $PORTNUMBER To: your-email@example.com Content-Type: text/plain; charset=utf-8 From: root@your-server-hostname.example.com (root) Message-Id:User-Agent: SSH Mailer for Linux by www.linuxmailserver.org (v1.4) X-Mailer: SSH Mailer for Linux by www.linuxmailserver.org (v1.4) X-Originating-IP: [IP ADDRESS] X-Original-Date: [DATE] at [TIME] UTC+[TIMEZONE] (via HTTP) X-Original-Server: [SERVER IP ADDRESS] at [SERVER PORT] (via HTTP) X-Remote-Addr: [REMOTE IP ADDRESS] (via HTTP) X-Remote-Port: [REMOTE PORT NUMBER] (via HTTP) X-Forwarded-For: [CLIENT IP ADDRESS] (via HTTP) X-Forwarded-Proto: http:// (via HTTP) X-Forwarded-Server: [SERVER IP ADDRESS] (via HTTP) X-Forwarded-Port: [SERVER PORT] (via HTTP) X-Forwarded-For: [CLIENT IP ADDRESS] (via HTTP) X-Forwarded-Proto: http:// (via HTTP) X-Forwarded-Server: [SERVER IP ADDRESS] (via HTTP) X-Forwarded-Port: [SERVER PORT] (via HTTP) X-Real-IP: [REAL CLIENT IP ADDRESS] (via HTTP) X-ClientIP: [CLIENT IP ADDRESS] (via HTTP) X-ClientHostname: [CLIENT HOSTNAME] (via HTTP) X-ClientProtocol: [PROTOCOL] (via HTTP) X-ClientPort: [PORT NUMBER] (via HTTP) Logged in user: $USER on host $HOSTNAME with IP address $IPADDRESS using protocol $PROTOCOL on port $PORTNUMBER at time $DATE at time $TIME from IP address $IPADDRESS via $PROTOCOL on port $PORTNUMBER. No active sessions found for this user. No failed login attempts found for this user. No successful login attempts found for this user. No unsuccessful login attempts found for this user. No command execution attempts found for this user. No file transfer attempts found for this user. No other activity found for this user. No active sessions found for this user. No failed login attempts found for this user. No successful login attempts found for this user. No unsuccessful login attempts found for this user. No command execution attempts found for this user. No file transfer attempts found for this user. No other activity found for this user. No active sessions found for this user. No failed login attempts found for this user. No successful login attempts found for this user. No unsuccessful login attempts found for this user. No command execution attempts found for this user. No file transfer attempts found for this user. No other activity found for this user. No active sessions found for this user. No failed login attempts found for this user. No successful login attempts found for this user. No unsuccessful login attempts found for this user. No command execution attempts found for this user. No file transfer attempts found for this user. No other activity found for this user. No active sessions found for this user. No failed login attempts found for this user. No successful login attempts found for this user. No unsuccessful login attempts found for this user. No command execution attempts found for this user. No file transfer attempts found for this user
網(wǎng)頁(yè)名稱:如何在Linux上為SSH登錄設(shè)置電子郵件提醒
文章出自:http://www.dlmjj.cn/article/djpogpe.html


咨詢
建站咨詢
