LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-10-2017, 04:49 AM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 241

Rep: Reputation: Disabled
Question install editor for use as root


I'm heartily sick of sudo nano blah blah blah, and I'd really rather not be bothered with sudo (insert editor name here) when I want to edit, for example, .bash_aliases.

In my LinuxMint, there is a "clone" of Krusader installed "as root user." I know from personal experience that other items, unless installed from scratch with the 'make install' file directing them to another place in the hierarchy, cannot be installed for anyone but the user profile I'm in without losing the original non-root install of the app. Is there a way to go from "downloaded .deb archive" to "same app but only for use as root" with apps other than Krusader?

Carver
 
Old 06-10-2017, 04:59 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,655
Blog Entries: 3

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
Something has gone wrong if you have root-owned files in your directory. Perhaps you need to run chown over your directory to fix that.

In general, if you have sudo, then you need to use sudoedit instead when editing file. It can be configured to point to your favorite editor. Because it runs the designated editor as an unprivileged user, you don't end up with root-owned files scattered all over making a mess. See the -e option in the manual page:

Code:
man sudo
 
Old 06-10-2017, 06:20 AM   #3
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918
First of all, you shouldn't be using sudo to run GUI applications as root. If you're running KDE, as your sidebar entry indicates, you should be using e.g. kdesudo nano (the equivalent command for Gnome-related desktop environments is gksudo nano).

Secondly you shouldn't, as TC points out, need root privilege to access files in your home directory. To regain ownership of all these, you can use (as long as you are currently logged in as your normal user):

Code:
sudo chown -R $USER:$USER $HOME
Lastly, you might like to create desktop shortcuts for applications that you want to run as root, using kdesudo/gksudo in the shortcut's command. Of course you will still have to enter the sudo password, so I hope that you're not also heartily sick of doing that.

If you want to run as root for a while (but, as always, be careful what you do), you can enter sudo su in a terminal - anything you do in that terminal from then on, until you close the terminal or enter exit, will be as root).

Last edited by hydrurga; 06-10-2017 at 06:22 AM.
 
Old 06-10-2017, 06:26 AM   #4
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,585

Rep: Reputation: 2351Reputation: 2351Reputation: 2351Reputation: 2351Reputation: 2351Reputation: 2351Reputation: 2351Reputation: 2351Reputation: 2351Reputation: 2351Reputation: 2351
Quote:
Originally Posted by L_Carver View Post
I know from personal experience that other items, unless installed from scratch with the 'make install' file directing them to another place in the hierarchy, cannot be installed for anyone but the user profile I'm in without losing the original non-root install of the app.
I'm sorry but this does not make any sense at all. Applications, and other programs, are generally installed so that every user can acces them and the settings for them are, if necessary, stored in the home directory of the user running them.
If you want to create a shortcut to run something as root then the answers are given above regarding gksu etc.
 
1 members found this post helpful.
Old 06-10-2017, 06:39 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,655
Blog Entries: 3

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
Quote:
Originally Posted by 273 View Post
If you want to create a shortcut to run something as root then the answers are given above regarding gksu etc.
Some discretion is needed about what to run as root and what not to run as root. Editors are one class of application that should only be used via an unprivileged account. If you do need to edit a file owned by root, then there is always sudoedit mentioned above.

From the manual page:

Code:
-e, --edit  Edit one or more files instead of running a command.  In lieu
                 of a path name, the string "sudoedit" is used when consulting
                 the security policy.  If the user is authorized by the pol‐
                 icy, the following steps are taken:

                 1.   Temporary copies are made of the files to be edited with
                      the owner set to the invoking user.

                 2.   The editor specified by the policy is run to edit the
                      temporary files.  The sudoers policy uses the
                      SUDO_EDITOR, VISUAL and EDITOR environment variables (in
                      that order).  If none of SUDO_EDITOR, VISUAL or EDITOR
                      are set, the first program listed in the editor
                      sudoers(5) option is used.

                 3.   If they have been modified, the temporary files are
                      copied back to their original location and the temporary
                      versions are removed.

                 To help prevent the editing of unauthorized files, the fol‐
                 lowing restrictions are enforced unless explicitly allowed by
                 the security policy:

                    Symbolic links may not be edited (version 1.8.15 and
                     higher).

                    Symbolic links along the path to be edited are not fol‐
                     lowed when the parent directory is writable by the invok‐
                     ing user unless that user is root (version 1.8.16 and
                     higher).

                    Files located in a directory that is writable by the
                     invoking user may not be edited unless that user is root
                     (version 1.8.16 and higher).

                 Users are never allowed to edit device special files.

                 If the specified file does not exist, it will be created.
                 Note that unlike most commands run by sudo, the editor is run
                 with the invoking user's environment unmodified.  If, for
                 some reason, sudo is unable to update a file with its edited
                 version, the user will receive a warning and the edited copy
                 will remain in a temporary file.
gksu will still cause the graphical program to run with root privileges, which depending on the situation makes for more trouble. Graphical programs with a lot of parsing of untrusted data are another category that should be avoided as root. wireshark is one such example.
 
Old 06-10-2017, 09:23 AM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by L_Carver View Post
I'm heartily sick of sudo nano blah blah blah, and I'd really rather not be bothered with sudo (insert editor name here) when I want to edit, for example, .bash_aliases.

In my LinuxMint, there is a "clone" of Krusader installed "as root user." I know from personal experience that other items, unless installed from scratch with the 'make install' file directing them to another place in the hierarchy, cannot be installed for anyone but the user profile I'm in without losing the original non-root install of the app. Is there a way to go from "downloaded .deb archive" to "same app but only for use as root" with apps other than Krusader?

Carver
Carver:
Have a look ****

How to install software on Linux Mint
If you compile - remember build-essential and checkinstall
Differences between gksudo/kdesudo, sudo, and su****
Differences between Update Manager, Synaptic, and "apt-get upgrade"

and a high-level overview of one person's recommendation on the use of sudo in the context of Security.
Sudo: you're doing it wrong - PDF @ 171 pages.
Sudo: you're doing it wrong - YouTubeVid @ 1h:11m

sudo, being an interactive prompted utility,
I avoid in scripts and once the script or user has privs,
there's little use for repeatedly using it.

Who's bash_aliases are you editing?
do those aliases have sudo in them or their named components?

Other useful authoritative sources are
https://help.ubuntu.com

I just think you need a crash-course in privileges

John.

Code:
gksudo krusader
and the sytem should issue a Proper Warning after the prompt.
You now have a root krusader. Have at it.

Last edited by Habitual; 06-10-2017 at 09:29 AM.
 
Old 06-10-2017, 11:08 AM   #7
DavidMcCann
LQ Veteran
 
Registered: Jul 2006
Location: London
Distribution: PCLinuxOS, Debian
Posts: 5,788

Rep: Reputation: 2140Reputation: 2140Reputation: 2140Reputation: 2140Reputation: 2140Reputation: 2140Reputation: 2140Reputation: 2140Reputation: 2140Reputation: 2140Reputation: 2140
Quote:
Originally Posted by hydrurga View Post
First of all, you shouldn't be using sudo to run GUI applications as root. If you're running KDE, as your sidebar entry indicates, you should be using e.g. kdesudo nano (the equivalent command for Gnome-related desktop environments is gksudo nano).
When you make statements like that, wouldn't it be more helpful to say why sudo nano is wrong and gksudo nano is right? I suspect the OP would like to know. For that matter, I'd like to know (very slightly), as I've never used sudo and don't have gksudo installed!
 
Old 06-10-2017, 11:22 AM   #8
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 5,561
Blog Entries: 16

Rep: Reputation: 3301Reputation: 3301Reputation: 3301Reputation: 3301Reputation: 3301Reputation: 3301Reputation: 3301Reputation: 3301Reputation: 3301Reputation: 3301Reputation: 3301
Quote:
Originally Posted by DavidMcCann View Post
When you make statements like that, wouldn't it be more helpful to say why sudo nano is wrong and gksudo nano is right? I suspect the OP would like to know. For that matter, I'd like to know (very slightly), as I've never used sudo and don't have gksudo installed!
As I understand it, the problem with sudo is that it gives the root user access to your personal environmental variables. That doesn't matter on the command line or in a simple desktop like fluxbox, but complex DEs are held together by a slew of XDG environmental variables, some of which could cause you to lose access to your files. It happened to me once; I couldn't get into X any more because the ownership of my .Xauthority file had somehow got transferred to root. I had to delete it as root so that X would create a new one in my name.

gksudo and kdesudo aren't just pretty graphical front ends. They actually protect your environment from root while they run.
 
1 members found this post helpful.
Old 06-10-2017, 11:28 AM   #9
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918
Quote:
Originally Posted by DavidMcCann View Post
When you make statements like that, wouldn't it be more helpful to say why sudo nano is wrong and gksudo nano is right? I suspect the OP would like to know. For that matter, I'd like to know (very slightly), as I've never used sudo and don't have gksudo installed!
No, because it would be taking the discussion off at a tangent from the OP's original request, and there's too much of that goes on anyway.

The OP is more than capable of searching on the web for the reasons why, or ask a further question, if they see fit to do so. A search for sudo gksudo, for example, produces the following as the first result:

https://superuser.com/questions/2026...udo-difference
 
Old 06-10-2017, 12:28 PM   #10
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,655
Blog Entries: 3

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
Quote:
Originally Posted by DavidMcCann View Post
When you make statements like that, wouldn't it be more helpful to say why sudo nano is wrong and gksudo nano is right? I suspect the OP would like to know. For that matter, I'd like to know (very slightly), as I've never used sudo and don't have gksudo installed!
In the case of editors, the answer is neither. See post #5 above.

For other graphical programs, you might use -H with sudo so that the program uses the root (or any other target) home directory.
 
Old 06-10-2017, 02:10 PM   #11
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 17,401
Blog Entries: 10

Rep: Reputation: 5212Reputation: 5212Reputation: 5212Reputation: 5212Reputation: 5212Reputation: 5212Reputation: 5212Reputation: 5212Reputation: 5212Reputation: 5212Reputation: 5212
i just found out that sudoedit can also be used with a graphical editor.
i wouldn't make the change permanent, because i think some command line applications expect EDITOR to be set to a command line editor.
but this is possible:
Code:
EDITOR="geany --new-instance" sudoedit /etc/somefile
 
1 members found this post helpful.
Old 06-16-2017, 12:17 PM   #12
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 241

Original Poster
Rep: Reputation: Disabled
Wink kdesudo not a problem

Quote:
Originally Posted by hydruga
Lastly, you might like to create desktop shortcuts for applications that you want to run as root, using kdesudo/gksudo in the shortcut's command. Of course you will still have to enter the sudo password, so I hope that you're not also heartily sick of doing that.
I'm the only user on this machine, and I've already (and a little sloppily) tweaked my sudoers file to accept my ordinary bash login as root, So kdesudo (editor name here) or as Turbocapitalist suggested, sudoedit seem to be the way to go.

Carver
 
Old 06-16-2017, 01:49 PM   #13
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,604

Rep: Reputation: 5604Reputation: 5604Reputation: 5604Reputation: 5604Reputation: 5604Reputation: 5604Reputation: 5604Reputation: 5604Reputation: 5604Reputation: 5604Reputation: 5604
you can define alias like this: alias suedit=sudo <your-editor>
and next you can type suedit filename and file will be edited by root.
(although I do not really suggest you to do that)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How do I change the default editor to use as root? nokangaroo Linux - Software 4 03-28-2011 05:54 PM
how to become root in a text editor r45 Linux - Newbie 11 08-10-2008 12:15 AM
Can't open text editor as root - SuSE 9.2 dcdbutler SUSE / openSUSE 9 02-17-2005 04:38 PM
Start a text editor as root?!? svarreby Slackware 10 02-25-2004 06:48 AM
Using Kate editor as root? guitarnix Linux - Newbie 3 09-18-2003 04:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration