Restart SSH on a machine where SSH is the only mode of access

Solution 1:

Restarting sshd while logged in via ssh will not disconnect your ssh connection.

If you're worried about your configuration, log in a few times via ssh, and restart. If you can no longer ssh in, with new connections, you now have access to fix the problems.

Mentioned below in a comment by @Milan Babuškov: sshd -t will test your configuration for syntax correctness, if you really want to be certain.

Another suggestion, by @Ronald Pottol was to set up a cron task to restart the server with a known working configuration. Perhaps overkill, but if you're updating a mission critical server, etc... sometimes you can never be too careful.

Solution 2:

If you have access to the hardware you may consider putting a terminal on the serial port /dev/ttyS0 . Then you can have a back door into your server.

simply add

SO:2345:respawn:/sbin/mingetty ttySO

to your /etc/inittab and a terminal will spawn over your serial port. You can use a serial port concentrator or use a null modem from the server next to it.


Solution 3:

Don't worry, your current session won't be disconnected, even if there's a problem with the new configuration.

After applying the new configuration and restarting sshd, just try to login a couple of times and take a look at the logs to see if everything is ok.


Solution 4:

Or, use a cron or at job to start it back up, if you are feeling unlucky?

Tags:

Linux

Ssh