Configuring System Log Email Notifications in CentOS
In CentOS, system services (like logwatch, cron, etc.) send log summaries and execution reports by default to the local root user's mailbox at /var/spool/mail/root. For easier management, you can forward these notifications to an external personal email address.
Configure Logwatch to Send Emails to a Personal Address
logwatch is a powerful log analysis tool that periodically generates system log summaries and sends them via email. To change its recipient address:
- Open Logwatch's main configuration file with a text editor (e.g.,
vi):vi /usr/share/logwatch/default.conf/logwatch.conf - Locate the line
MailTo = root. - Change it to your personal email address, for example:
MailTo = [email protected] - Save and exit the editor.
Additional Configuration and Notes
Other services (like cron) also rely on the system's Mail Transfer Agent (MTA, such as sendmail or postfix) for email notifications. Ensure your MTA is correctly configured to send mail to external networks.
To forward all mail sent to the local root user to an external address, you can configure the system's mail aliases. Edit the file /etc/aliases and add the line:
root: [email protected]
Then run the command newaliases to apply the changes.
Verify the Configuration
After configuration, send a test email to verify:
echo 'Test mail from CentOS' | mail -s 'Test Subject' root
Wait a moment and check your personal inbox for the test message.