-1

I am trying to run a cron job that runs every 10 minutes to kill the process sshd.

so I did open /etc/crontab as a root and inserted the following line.

*/1    *     *      *    *    pkill sshd

I checked with systemctl status sshd after 1,2,3 minutes. And I see sshd still up & running.

I am using centos7.

  • 2
    Isn’t there a * missing? – nohillside Jan 12 '18 at 20:43
  • Yes I added the start and still the same issue – alkabary Jan 12 '18 at 20:58
  • what exactly are you trying to do? disable ssh? better methods. kick off idle ssh connections? better methods. edit your question and tell us your end goal and we can give better help. – ivanivan Jan 12 '18 at 23:04
0

There are several problems here (are you sure you wouldn't be better off using auto logoff?):

*/1   *    *   *    *    pkill sshd

The "/1" should be "/10" to run every ten minutes.

There is no user specification: I suspect that you'll find some message to the tune of "unknown user pkill" in the syslog.

It's to be seen whether pkill is in cron's PATH when it runs.

All in all, I'd try with:

*/10  *    *   *    *    root    /path/to/pkill sshd

Then you have the problem of sshd restarting after having been killed, as D'Arcy Nader pointed out in his answer (but that's probably all right, otherwise you wouldn't want to do serial killing through cron).

2

you have to edit the file sshd.service and change the line from:

Restart=on-failure

to

Restart=no

and when you'll kill the process it will not restart.

2

Why don't you just stop the process all together? etc/init.d/sshd stop If you you are worried it will start up on the next reboot, you could add this command to crontab via crontab -e add */1 * * * * etc/init.d/sshd stop . This is untested at the moment.

https://www.centos.org/docs/5/html/Deployment_Guide-en-US/ch-autotasks.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.