68

Im trying to make a shortcut to login my ssh server:

ssh x.x.x.x

I made the following file:

ssh_home.sh

Made it executable:

sudo chmod +x ./ssh_home

Checked by right clicking properties to check if it was executable and it was..

But whatever I do, when double clicking it, it will launch gedit. I tried "Open With" but no terminal app is shown there. I searched the net but only found a way to link to the file while not integrating it in one "shortcut file"

9
  • 4
    Did you add #! /usr/bin/sh at the beginning of the file (the first line)?
    – Misery
    Commented May 23, 2013 at 11:50
  • Out of interest, what version of Ubuntu are you running? In principle it should be just a case of marking the file as executable in Properties/Permissions, but on 13.04 this seems not to work for me (even directly on the .sh file, with #! /bin/bash at the start...)
    – Jez W
    Commented May 23, 2013 at 11:59
  • Also check owner and permissions. Does user clicking it have permission to run it?
    – Misery
    Commented May 23, 2013 at 12:04
  • 1
    Your commands can't be correct - You're referring to ssh_home.sh and /ssh_home, which are not the same files.
    – l0b0
    Commented May 23, 2013 at 12:04
  • 2
    @Misery: It's /bin/sh, not /usr/bin/sh. (/usr/bin/sh will happen to work on systems where /bin and /usr/bin are the same directory; I don't think that's the case for Ubuntu>) Commented Jul 10, 2015 at 21:05

6 Answers 6

62

I think it would be better to use a launcher file for your script by creating a ~/Desktop/ssh_home.desktop file with the following contents:

[Desktop Entry]
Version=1.0
Exec=/home/yourname/bin/ssh_home.sh
Name=SSH Server
GenericName=SSH Server
Comment=Connect to My Server
Encoding=UTF-8
Terminal=true
Type=Application
Categories=Application;Network;

That way you will have a clickable icon which will launch your script.

You may have to also set the executable flag with chmod:

chmod +x ~/Desktop/ssh_home.desktop
6
  • 1
    This method IS working but I prefer a 1 file solution...
    – michel
    Commented May 23, 2013 at 14:16
  • 10
    @michel If all the script does is run ssh host, you don't need the script, just change the Exec line to Exec=ssh host.
    – geirha
    Commented May 23, 2013 at 18:33
  • 1
    This is the only solution that worked for me.
    – Aviad P.
    Commented Aug 26, 2015 at 16:50
  • I get Untrusted application launcher message box and it doesn't run my command.
    – Matt
    Commented Dec 27, 2018 at 20:00
  • 1
    @Matt try right clicking on the icon, go to Properties > Permissions then select Allow executing file as program. Also if you copy and pasted the text above into your file, make sure there isnt any trailing whitespace after the lines. That may cause your error message. Commented Jan 18, 2019 at 18:38
57

I know this is a while ago but though if someone else asks I have this answer.

  1. Open nautilus
  2. Files menu -> behaviour tab
  3. Run executable text files when they are opened

In later versions this option is found at: Files menu -> Edit -> Preferences -> behaviour tab

In Ubuntu 14.10 move the mouse to the top of the screen and the File, Edit etc... Menu bar appears. Click EDIT -> Preferences -> Behaviour tab

6
  • 2
    This should be the accepted answer IMHO. I was getting rather frustrated trying to figure out why I could not run the shell script from Nautilus. Commented Aug 16, 2014 at 0:12
  • 1
    What is Files menu? Never seen it. Commented Mar 29, 2015 at 16:27
  • 4
    One complication is that this affects all executable files. (That might be what you want.) Commented Jul 10, 2015 at 21:06
  • 1
    Great answer! On Ubuntu 18.04, I set it to 'Ask what to do', so I can choose to run or display it every time I double click such a file. Thanks!
    – MS Berends
    Commented Feb 10, 2019 at 16:31
  • 1
    Note that this option doesn't exist anymore in Ubuntu 22.04
    – Thierry J
    Commented Jun 30, 2022 at 13:04
3

The "trap" for me was that I searched via right-clicking on the file for a way to change the behaviour (to have a script run instead of opened in gedit). Don't right-click ! Rather open from the "regular" menu-bar:

Edit-Preferences-Behaviour and change to "run" or "ask each time".

Comment: For my taste there should be a way to run a program via right-clicking too. Especially since right-clicking leads to the menu "open with", which makes you search for "open with bash", however "bash" is not included as an option...

1
  • For my taste also...
    – Marecky
    Commented May 10, 2017 at 16:37
1

imo the simplest answer is -

  1. Check that the .sh file works if clicked or run from its own directory.
  2. If it works there, right-click on it in Files aka Nautilus, select 'Make Link'
  3. This produces a file named 'link to xxxx.sh' in the same directory
  4. Drag this onto the desktop
  5. Rename it how you wish eg clean off 'link to' and 'sh', just leave the name, it will still work.
1
  • Also you can change the icon of the link too. Right-click it, select Properties, click the default icon in the upper left part of the properties window, and so just navigate until you find the image your want to be the icon. Commented May 24, 2017 at 4:07
1

I'd say the easiest way to add a shell script to the shortcuts would be to add the .sh file to the home directory. Once copied to the home directory just go to custom shortcuts and add the command sh yourfile.sh

This was my work around hope it helps you

0

Ubuntu 20.04

open file manager (aka Nautilus) click hamburger menu, top right (three horizontal bars) choose Preferences click Behaviour tab under Executable Text Files, choose your preference. (Ask What to do lets you choose each time and file)

1
  • 1
    This is a poor copy of the most upvoted answer.
    – zx485
    Commented Jul 10, 2021 at 2:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .