- Forum
- Linux Forums
- [Solved] How to delete all standard logs on a Linux server regularly to keep it clean of logs?
Advertisement: Linux VPS from $4/month - contact support for custom offer.
-
Administrator
How to delete all standard logs on a Linux server regularly to keep it clean of logs?
How to delete all standard logs on a Linux server regularly to keep it clean of logs?
This is an idea on the command:
cd /var/log;rm -rf audit;rm -f dmesg.*;rm -f messages-* cron-* maillog-* secure-* ~/.viminfo /var/log/http*/*log;[ -f auth.log ]&&>auth.log;[ -f messages ]&&>messages;[ -f maillog ]&&>maillog;[ -f cron ]&&>cron;[ -f secure ]&&>secure;[ -f wtmp ]&&>wtmp;[ -f btmp ]&&>btmp;[ -f dmesg ]&&>dmesg;[ -f lastlog ]&&>lastlog;[ -f syslog ]&&>syslog;[ -f lynis.log ]&&>lynis.log;[ -f fail2ban.log ]&&>fail2ban.log;>~/.bash_history;history -c;
It can be run as a cronjob (crontab -e) by prefixing it by "* * * * * " to run it every minute.
(if one run app that scans failed SSH login attempts in log files (like DenyHosts do), one may need to edit above command and move auth.log pattern into new line that will be run less often to allow DenyHosts to work:
*/15 * * * * cd /var/log;[ -f auth.log ]&&>auth.log
Disable history of typed command outside of current login session:
>$HISTFILE;export HISTFILE=;echo "export HISTFILE=" >> ~/.bashrc
Disable system messages logging appending "*.* stop" to rsyslog.conf (run as root, else prefix all commands by "sudo"):
echo "*.* stop"|tee -a /etc/rsyslog.conf && systemctl restart rsyslog.service && systemctl status rsyslog.service
Disable OpenVPN server logging (if/after have openvpn server installed):
for f in $(find /etc/openvpn/ -name server.conf);do sed -e '/openvpn-status.log/d' -e '/verb /d' "$f" && echo -e "log /dev/null\nstatus /dev/null\nverb 0" >> "$f"; done;systemctl restart openvpn-server*
Which other approach do you suggest to keep Linux server (Ubuntu or CentOS) clean of default logs?
Which other approach do you suggest to keep Linux server (Ubuntu or CentOS) clean of default logs?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Protected by : ZB
BLOCK & StopForumSpam
Bookmarks