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]
Exec=gnome-terminal --geometry=... --window-with-profile=... --title=... -e 'bash -c "ssh -t -i ~/dsa.key cle@ sudo -s"'
  • how to do this programmatically? Instead of using the GUI. – MrCholo Dec 15 '18 at 0:56

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@ 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@ sudo -s; read line"'


  • 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.
  • But this affects all terminals. – A.B. Jun 1 '15 at 5:00
  • @A.B. It does, but is that a problem? – Jacob Vlijm Jun 1 '15 at 5:00
  • I would say yes. – A.B. Jun 1 '15 at 5:02
  • @A.B. added another option. – Jacob Vlijm Jun 1 '15 at 5:58
  • 1
    Why not create a special profile with "not quit as command end" and call that profile with gnome-terminal --profile=myprofilenoendcmd ? – solsTiCe Jun 1 '15 at 8:07

I played around with this code for a few minutes. I think I found a solution. Here is my (a bit oversimplified when it comes to the details) code:

[Desktop Entry]
Exec=gnome-terminal -e 'bash -c "ssh"' && gnome-terminal --geometry=... --window-with-profile=... --title=... -e 'bash'

Hope this helps!

I just added a line of code executing gnome-terminal with raw bash using the && command.

EDIT: I just realized someone already solved it!! Oops!

  • This helped me - basically just needed to rerun the same gnome-terminal command without the -e option. I tried like 15 different techniques before landing on this one. – Ryan Wheale Dec 3 at 2:37

You can do this by simply adding '$SHELL' variable at the end of your command. See below example in Exec=.... line.

[Desktop Entry]
Name=MDS Control
Exec=gnome-terminal -e "bash -c 'Your command;$SHELL'"

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.