I have a script for getting Clamav updates from another server which I run as a Cron job as root. Also, I have root login disabled for
/sbin/nologin. But this has serious implications on the system as it stops the sshd service, deletes the /bin/bash login for my user. These are the steps I took to reach this state:-
- Create any executable script int /root/. In my case it was a script to update Clamav.
- Make sure root login is disabled by changing root user's shell from /bin/bash to /sbin/nologin.
- Manually add an entry in /etc/crontab to run this script every minute with user as root.
- Now restart ssh service and try sshing in after 5 mins.
* * * * * root /root/clamu.sh >/dev/null 2>&1
Following is the
#this script need to run by root user #create a folder temp mkdir /temp #go to the temp dir cd /temp #clean this folder rm -f * #Copying the files from server to temp dir scp -P 2277 firstname.lastname@example.org:/var/lib/clamav/daily.* . scp -P 2277 email@example.com:/var/lib/clamav/bytecode.* . #Updating the files to actual location rm -f /var/lib/clamav/daily.* cp -u daily.* /var/lib/clamav/ cp -u bytecode.* /var/lib/clamav/ #do scanning & save report cd / clamscan --recursive=yes >> /var/log/clamav/clamd.log # Clean the /temp folder cd /temp rm -f *
I am using
CentOS 7 x64. Although I don't think it is related to the distribution but is a common problem.
I know the problem is caused by running this script as root in cron somehow. But why is it causing ssh failures and kernel panics is what I want to know, just to learn what is going on. I am an amateur Linux user and would certainly appreciate some explanation. Thanks.
EDIT Hi, since I have not shown any research efforts that is because this was not the initial problem. This occurred in one of my remote VMs, and I had no logs to debug it. After figuring out how to access the logs, I did try to fix the problem and I was able to fix it by using different user in the crontab entry. But the question still remains, How can a cron job cause so much destruction. That is what I need an answer to, or even a direction so that I could find out.