Keep GNOME Terminal Open – How to Keep GNOME Terminal Open After Program Closes

command linedesktopgnome-terminal

I have the following shortcut which opens an SSH instance. How can I modify it so that when SSH closes, the terminal stays open?

[Desktop Entry]
Terminal=true
Type=Application
Name[en_US]=ssh
Icon=/logo_sprite.png
Exec=gnome-terminal --geometry=... --window-with-profile=... --title=... -e 'bash -c "ssh -t -i ~/dsa.key cle@12.210.9.17 sudo -s"'

Best Answer

1. First option: edit gnome-terminal settings

In gnome-terminal, go to preferences, the "Title and command" tab. Then click the drop-down list "When command finishes", choose "Keep terminal open".

enter image description here


2. If you prefer not to have an effect on all terminals

You can add bashas a last command. In my test,

Exec=gnome-terminal -e 'bash -c "gedit; echo Monkey; bash"'

did the job. In your command, you probably need to do it like:

Exec=gnome-terminal --geometry=... --window-with-profile=... --title=... -e 'bash -c "ssh -t -i ~/dsa.key cle@12.210.9.17 sudo -s; bash"'


3. Keep the terminal open until you hit Enter

Another option is to place read line at the end of your commands. In that case, the terminal will stay open until you hit Enter

From my test:

Exec=gnome-terminal -e 'bash -c "gedit; echo Monkey; read line"'

Or in your command probably:

Exec=gnome-terminal --geometry=... --window-with-profile=... --title=... -e 'bash -c "ssh -t -i ~/dsa.key cle@12.210.9.17 sudo -s; read line"'

Notes

  • Note that this launcher will "steel" possible other windows from gnome-terminal's own application launcher in the Unity Launcher, since this launcher calls gnome-terminalin its "main" command. Cleaner would be to add the command as a shortcut to the existing gnome-terminal launcher (or any other launcher you'd like).
  • Since the command in the launcher already calls gnome-terminal, you do not need to set Terminal=true.
Related Question