You were updating some *nix firewall rules or network configs over a remote connection and changed the wrong setting. Oops, now you’re locked out and feeling helpless.
Next time, follow the steps below to undo your network mistakes and avoid getting locked out permanently. The example commands illustrate how you’d recover from fucking-up a sshd_config change.
Upon connecting to the remote server, immediately make a backup of the file(s) you need to modify.
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.old
Schedule a job to run later with the at
command that reverts the changes you’re about to make, ensuring you set enough time to actually make those changes!
at now + 5 minutes <<< 'cp /etc/ssh/sshd_config.old /etc/ssh/sshd_config; service sshd restart'
In the above example, the backup configuration file will be restored, the service is restarted, and things are back to normal within 5 minutes.
If your changes worked, move on to the next step.
So your changes (finally) worked out, don’t forget to cancel the “undo” job! Commands queued up for later execution via at are listed with the atq
command and deleted with the atrm
command.
Find the “Undo” Job Number:
atq
Delete the “Undo” Job:
atrm 1
Replace ‘1’ with the relevant job number found via atq