OpenSSH may hang when exiting. This can occur when there is an active background process. The problem can be verified by executing the following command:
$ sleep 20 & exit
Try to use this instead:
$ sleep 20 < /dev/null > /dev/null 2>&1 &
A work around for bash users is to place “shopt -s huponexit” in
either /etc/bashrc or ~/.bashrc. Otherwise, consult your shell’s man page for an option to enable it to send a HUP signal to active jobs when exiting.