10

Is there a way to automatically run as gksudo when I click on the Sublime Text icon?

0xF2
  • 3,154

6 Answers6

8

Sublime Text should have a .desktop file located in /usr/share/applications/ named sublime-text.desktop.

Open it and change the Exec= line to include gksu (or gksudo they are the same) at the beginning.

enter image description here

Now unpin and repin the sublime text icon to the launcher.

NOTE: Your path to the sublime executable will probably be different, that's because I installed the Sublime 3 beta, don't worry about it, just add gksu.

Seth
  • 58,122
  • 1
    I'm using 14.04 and sublime text 3, the file .desktop for sublime now called sublime_text.desktop – rails_id Jun 21 '15 at 16:24
  • 2
    didn't work for me until I realized I didn't have gksu installed. A simple sudo apt-get install gksu took care of that, and now it's working as expected. – Chris Dec 28 '15 at 10:14
2

gksudo - is graphical sudo. For instance you won`t see Password dialog if you run command "sudo nautilus" using Alt+F2 You may make a script (sh file)

#!/bin/bash
gksudo /usr/bin/<your_app>

Then

chmod +x <your scrypt.sh>

And then run it in Nautilus (check option "ask what to do when opening executable files" in settings)

yanpas
  • 543
  • 4
  • 16
2

Like Seth said, Sublime Text should have a .desktop file located in /usr/share/applications/ named something like sublime-text.desktop.

You can then open it up and change the exec= line to include gksudo at the beginning, so it should now look like this: gksudo <command already there for starting Sublime-text>.

While this will automatically launcher Sublime text with the gksudo window, you will still have to enter your password each time, which isn't what you want.

However, what you want is possible to do, but the only way I can think of would introduce a pretty serious security risk.

You would have to turn off the sudo timeout, which allows basically anything to run as sudo, without your permission, which basically defeats the entire purpose of the sudo password. Check out this question for some possible help with that.

All in all, I know of no way to do what you want entirely safely. If you don't mind risking your system a little, it can be done via turning off the sudo timeout, but I highly recommend against that.

You would still have to enter the sudo password each time you log on, but by turning off the sudo timeout you wouldn't have to enter it again until you logged out or rebooted.

1

update 2020-06-27: gksu is deprecated and has been removed for security concerns. see I need an equivalent of gksu in 18.04

long story short:

sudo -H subl

note that the sudo -H is simple enough but it suffers the same security issues as gksu. better option (for reasons beyond my understanding) would be pkexec. there's also admin:// protocol but it didn't work for me with sublime.

oriadam
  • 126
0

I know you asked for every time, people reading this if you want to just launch it once as root try

sudo subl

Do Not Use. See comments.

jalbasri
  • 111
0

I stumbled across this via a Google search. I know this doesn't answer the OP's original question, but it is for anyone that used the same query as I.

The accepted answer didn't work for me. I just ran sublimetext from the command line with gksudo.

gksudo /usr/bin/subl

BrianRT
  • 111
  • 1
    The reason this is incorrect and the accepted answer is correct is because the question is to default the application to run as gksudo. What you wrote will work to run sublime as sudo but it will not default the app to run as sudo when it is opened via icon. – ford prefect Apr 26 '16 at 19:40