stackOverlord
stackOverlord

Reputation: 5402

use ssh to kill and restart all sshd processes

I have a script that will

  1. kill all sshd processes
  2. start a new sshd process

I would like to scp this script onto a remote computer and execute it using ssh. After it executes the first step of killing all sshd, will it still get to the 2nd step of running sshd again? I'm worried because I'm running the script using ssh and ssh will die after step 1.

Upvotes: 0

Views: 2847

Answers (3)

idobr
idobr

Reputation: 1647

Why not to use cron for it? For example:

10 * * * * /path_to_script

minute hour day month dayofweek command

Do not forget to switch it off;)

Upvotes: 0

that other guy
that other guy

Reputation: 123460

Normal procedure is to stop the main sshd, with e.g. /etc/init.d/sshd stop or your distro's equivalent. This way, the listening daemon shuts down while existing connections go on until the clients disconnect.

If you want to upgrade/replace sshd, change any settings and restart it, this is the way to go.

Upvotes: 2

Gilles Quénot
Gilles Quénot

Reputation: 185053

No need to scp it to server, just try doing this :

while read cmd; do ssh server "bash -c $cmd"; done < script.sh

Upvotes: 0

Related Questions