SOLVED - How to run Sublime Text with root permission?

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
iain_33
Level 3
Level 3
Posts: 157
Joined: Sat Dec 22, 2018 11:29 am
Location: UK

SOLVED - How to run Sublime Text with root permission?

Post by iain_33 »

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 LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Linux Mint 19.3 Cinnamon on Lenovo Legion Y540 laptop (2020)
User avatar
xenopeek
Level 25
Level 25
Posts: 29597
Joined: Wed Jul 06, 2011 3:58 am

Re: How to run Sublime Text with root permission?

Post by xenopeek »

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 3
Level 3
Posts: 157
Joined: Sat Dec 22, 2018 11:29 am
Location: UK

Re: How to run Sublime Text with root permission?

Post by iain_33 »

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.3 Cinnamon on Lenovo Legion Y540 laptop (2020)
User avatar
xenopeek
Level 25
Level 25
Posts: 29597
Joined: Wed Jul 06, 2011 3:58 am

Re: How to run Sublime Text with root permission?

Post by xenopeek »

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 3
Level 3
Posts: 157
Joined: Sat Dec 22, 2018 11:29 am
Location: UK

Re: How to run Sublime Text with root permission?

Post by iain_33 »

I see ... I'd assumed it was Linux-native along with the other editors.
Linux Mint 19.3 Cinnamon on Lenovo Legion Y540 laptop (2020)
Locked

Return to “Software & Applications”