I use the following command:
ssh -t <hostname> 'sudo shutdown --reboot 0 && exit'
Here is what this is doing:
- It instructs the machine to reboot in the next moment, but not during this command
- Exits cleanly from SSH
- Maintains the SSH TTY the entire time so sudo is happy and can execute properly.
Hope that helps.