I have defined in gnome-terminal that it closes at end of shell. When I press Control-D or I execute exit, the terminal closes.

But if I open the SSH session with gnome-terminal -x ssh server and I execute reboot in the SSH session (to reboot the remote server), it hangs and it doesn't close. What's happening?

This worked to me before but I have to reinstall my Ubuntu (in local) and now gnome-terminal doesn't close itself when SSH session ends.


Add this to your remote server's ~/.bashrc or ~/.profile, whichever is appropriate:

alias reboot='{ sleep 2; reboot; }& exit'

Every time you type 'reboot' on the remote server, it tells the computer to reboot in 2 seconds, while immediately exiting, ensuring your terminal won't just hang.

Edit: have I misunderstood your question?

To close your terminal, after a SSH session ends, use an alias for sshing your server, and append 'exit' to the end:

alias server_ssh='ssh user@site.com; exit'

Put that in your ~/.bashrc


The ssh server dies without properly closing the connection. The client will sit there because it doesn't know anything has happened to the server. The server has just remained quiet for a while; this is indistinguishable from the server being there but having nothing to say. Eventually the client will send a test packet, receive no reply, and die. You can hasten that by pressing a key; the client will send a real packet, receive no reply, and die. Or you can forcibly close the connection on the client by pressing Return then ~..

  • Is the problem in SSH server? – Juan Simón Oct 23 '11 at 1:09
  • Think about it, if the server goes offline, how can it properly close the session? – Matt Oct 23 '11 at 1:11
  • When I reboot the server, it closes all services, included ssh server. In that moment, gnome-terminal should close itself. This worked before I reinstall my system (in local). – Juan Simón Oct 23 '11 at 1:18
  • @Simón Everything is working as designed. reboot does the minimum to reboot as soon as possible while not leaving the system in an inconsistent state. This doesn't include giving user applications such as running SSH session a grace time to close gracefully. – Gilles 'SO- stop being evil' Oct 23 '11 at 1:20
  • It doesn't satisfy your responses. If this worked to me before, it should work now too. The problem must be in some misconfiguration or in a bug. – Juan Simón Oct 23 '11 at 1:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.