A safer way to edit files as root using a gui editor


#1

Set the environment variable VISUAL=kate (kate as an example)
Since now, everytime you want to edit a file as root, just type into the terminal: sudoedit /path/to/file

Pros:

  • Safer
  • The gui editor launches with the current user’s configuration.

(according to this blog post)


#2

I hate this solution …


#3

Could you tell why?


#4

Because instead to implement a good working functionality:

  1. browser to the file
  2. click on
  3. it opens with kate
  4. you edit the file
  5. you save it
  6. it’ll ask you for root permissions when needed
  7. saved

they break the normal workflow to force a ■■■■■■■■ solution where a normal user needs to set an env-variable and still has to think about how to use it …


#5

No no. Just sudoedit /path/to/file … edit … ctrl+s to save.


#6

you can also do
EDITOR=featherpad sudo -e /path/to/file

  • replace “featherpad” with the GUI editor of your choice. if no editor is specified, a CLI editor gets used.
  • /path/to/file is supposed to give the path to a file, which can only be edited by root.

#7

yeah … But “when you change something, change it for the better”. Now we have just a breakage in the workflow. Nothing is better. Thats why i hate this Change.

Also my sudoedit defaults to nano. (wich is what i want).


#8

This tutorial is just for people who like using a gui editor.


#9

i would like to use kate for all my files, but its tbh just stupid that i need to the terminal to open kate…

When a graphical editor, then the whole way should be possibe graphical …


#10

what about Rightlick on the file --> admin-action --> edit as textfile (it works on KDE)


#11

That is what I like about dolphin right-click root actions.

That is my Gui way and I understand what Martin Gräßlin is saying. And what his concerns are.
But for me theoretical attack vectors for nonexistent virus or malware doesn’t get my attention much.
As the reality is the process of me getting things done.

And am not going to have a terminal open using terminal commands and scripts to do it the terminal way to launch Gui apps. Just seems a backwards or awkward way of launching apps. Can tell me I’m doing it wrong and not the way to do it and all that. But isn’t going to change my already ingrained behavior.


#12

That will run kate as root.


#13

so perfectly what you want without doing anything stupid :wink:


#14

Thats for me also just a workaround. This needs to be implemented in the editor or frameworks and really needs to ask just in case we need more permissions

https://bugs.kde.org/show_bug.cgi?id=376624

a good situation would be:

i open kate to write a new script (that is do often :joy:). Since i need this script for a PKGBUILD i’ll save it to ~/projects/git/PKGNAME/scriptname, but since i want to test it, i’ll also save it to /usr/bin/scriptname.

Now the situation is the following

##sudoedit

  • it will not even start kate, because you need to provide the savinplace at first and it needs to be outside your home directory

##sudo/kdesu

  • the scriptfile inside your PKG directory will be savedas root and you need to chmod/chown it

##as user

  • you can not save in /usr/bin

#15

Ok, this is just one of many ways to do a same thing. Choose whatever you like.


#16

Too stupid, why don’t you create a symlink:
# cp -s ~/projects/git/PKGNAME/scriptname /usr/bin/scriptname


#17

because usually i dont need the same file on both directories but a slightly different version.

Take my new steam client, while i had in the pkgbiuilddirectory always the real bath to everything, i was for the testing files in my filesystem on realpath_test. Its also not good to have for everyone writable scripts/files in PATH


#18

if you’re gonna sudo launch a gui app from command line, shouldn’t you be using gksu anyway?


#19

{deleted} proly dumb question anyway :wink:


#20

Not arguing, I understand there are several ways of doing it, just as beginner myself I’m trying to understand, why is this easier or better for beginner than say just running this command:

gksu gedit /etc/default/grub
kdesu kate /etc/default/grub

I probably don’t understand some underlying mechanics and my question may sound silly.

Sorry @trmdi, did it (asked) anyway :-)))