SOLVED - How to run Sublime Text with root permission?

Questions about applications and software
Forum rules
Before you post please read how to get help
Post Reply
iain_33
Level 2
Level 2
Posts: 70
Joined: Sat Dec 22, 2018 11:29 am
Location: UK

SOLVED - How to run Sublime Text with root permission?

Post by iain_33 » Sat May 25, 2019 12:32 pm

I've settled on Sublime Text as my editor of choice, but can't seem to get it to open files with root permission. Eg. /etc/fstab:

I've tried /opt/sublime_text/sublime_text admin:///etc/fstab but it opens up a blank file called ~/admin.

Tried pkexec /opt/sublime_text/sublime_text /etc/fstab, it asks for my password, then nothing happens after I enter it.
Last edited by iain_33 on Tue May 28, 2019 4:47 am, edited 1 time in total.
Linux Mint 19.1 MATE (64 bit) on a HP G70 laptop (circa 2008)
Intel Pentium Dual Core T3400 @ 2.16GHz -- 3GB RAM -- 1TB HDD
Intel Mobile 4 Series graphics -- Intel 82801I audio
Atheros AR242x/AR542x wireless network adapter

User avatar
xenopeek
Level 24
Level 24
Posts: 24133
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: How to run Sublime Text with root permission?

Post by xenopeek » Sat May 25, 2019 2:18 pm

I'd use sudoedit for this, which is what it exists for.

To try it out first run this command to define your default editor for sudoedit:
export SUDO_EDITOR="/opt/sublime_text/sublime_text -w"
Then try editing /etc/fstab from the same terminal session with the command:
sudoedit /etc/fstab

This should do what you want in a different way:
- the sudoedit command makes a writable copy of the /etc/fstab file
- then opens sublime_text to edit the writable copy and says to wait (-w option) till you close the file in sublime_text
- after you close the file in sublime_text and you made changes sudoedit will copy it to original location
- only sudoedit runs as root; sublime_text runs as normal user

If this indeed does what you want edit your ~/.bashrc file and at the end add the first command we used:
export SUDO_EDITOR="/opt/sublime_text/sublime_text -w"
That way on any future terminal you open sublime_text is set as your default editor for sudoedit.
Image

iain_33
Level 2
Level 2
Posts: 70
Joined: Sat Dec 22, 2018 11:29 am
Location: UK

Re: How to run Sublime Text with root permission?

Post by iain_33 » Sat May 25, 2019 2:59 pm

Hi xenopeek, thanks for your reply, that works, albeit opening the file with a temporary filename - I'd have to remember what it "really is" if I had several open.

I'm curious about why admin:// & pkexec don't work, when they do for all the other editors?
Linux Mint 19.1 MATE (64 bit) on a HP G70 laptop (circa 2008)
Intel Pentium Dual Core T3400 @ 2.16GHz -- 3GB RAM -- 1TB HDD
Intel Mobile 4 Series graphics -- Intel 82801I audio
Atheros AR242x/AR542x wireless network adapter

User avatar
xenopeek
Level 24
Level 24
Posts: 24133
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: How to run Sublime Text with root permission?

Post by xenopeek » Sat May 25, 2019 4:05 pm

The Sublime Text developers apparently haven't integrated polkit support into their software, which is needed for that to work. A common issue with commercial, closed source, cross-platform software; Linux doesn't get prime attention and because the community can't get involved (as it's closed source) it takes a long time for such software to catch up, if ever, with what have otherwise long become ubiquitous standards for Linux desktop applications.
Image

iain_33
Level 2
Level 2
Posts: 70
Joined: Sat Dec 22, 2018 11:29 am
Location: UK

Re: How to run Sublime Text with root permission?

Post by iain_33 » Sat May 25, 2019 5:55 pm

I see ... I'd assumed it was Linux-native along with the other editors.
Linux Mint 19.1 MATE (64 bit) on a HP G70 laptop (circa 2008)
Intel Pentium Dual Core T3400 @ 2.16GHz -- 3GB RAM -- 1TB HDD
Intel Mobile 4 Series graphics -- Intel 82801I audio
Atheros AR242x/AR542x wireless network adapter

Post Reply

Return to “Software & Applications”