Anytime you want to exit the Terminal (or sever your ssh connection), just type exit. If you’re every in a territory where exit isn’t letting you exit, try quit or q.