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

- 3,154

- 215
-
1For your second question: http://askubuntu.com/q/11760/44179 – Seth Feb 25 '14 at 19:34
6 Answers
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.
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
.

- 58,122
-
1I'm using 14.04 and sublime text 3, the file
.desktop
for sublime now calledsublime_text.desktop
– rails_id Jun 21 '15 at 16:24 -
2didn't work for me until I realized I didn't have
gksu
installed. A simplesudo apt-get install gksu
took care of that, and now it's working as expected. – Chris Dec 28 '15 at 10:14
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)

- 543
- 4
- 16
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.

- 9,783
-
I don't mind typing my password in I just want it to automatically run as administrator. Thanks for your help – ford prefect Feb 25 '14 at 19:49
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.

- 126
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.

- 111
-
Bad idea - never run GUI apps with plain
sudo
- it might give you troubles on the next login - see problems with.Xauthority
– guntbert Jun 15 '14 at 20:19 -
http://askubuntu.com/questions/11760/what-is-the-difference-between-gksudo-nautilus-and-sudo-nautilus – ford prefect Jun 16 '14 at 12:54
-
Thanks, for correcting me.When I run gksudo subl though sublime text does not launch. – jalbasri Jun 16 '14 at 13:22
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

- 111
-
1The 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