Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ubuntu - How to enable "sudo" in gui tools after starting?

Status
Not open for further replies.

MrCBofBCinTX

Technical User
Dec 24, 2003
164
US
Linux Newbie here.
How can I use the gui tools in ubuntu to (for example)edit files my login doesn't have permission to? I know how to sudo from the command line, but what's the point of the gui tools if you can't get access to files once you get there without logging in as root or using the command line? Some of the GUI tools ask for password but many don't seem to have any options after-the-fact except re-starting them from the command line with sudo. Am I missing something?
 
... and most of the time I can't figure out the command line arguments to start the GUI tools.

I'm very interested in an answer to this, too.
 
You're not missing anything. As you said, some applications are smart enough to prompt you when you need root access, but there is no solution for programs that aren't. In general, once the application is running, it's already too late to get root access.

If you just want to start applications as root without resorting to the command line, you can use the gksu (in GNOME) or kdesu (in KDE) program to get a graphical password prompt. You can add this to the shortcut for a program you need to run as root. You can also use these to create an "open as root" context menu item for your file manager.
 
If you want to hack about with your environment all the time just log in as root and use it like you would a windows PC, logged in with administrator rights.
If you know what you want set up but don't want to be logged in as root all the time, login as root and hack away, then for the rest or the time login as a non root user.
 
Thanks,
I was afraid that was the case.
how do I add the "open as root" context menu item? That ought to be enough to make life a lot easier
 
I think in the case of editing files, you can open a terminal as user "someone", sudo su in the terminal, and then "gedit file.txt" as root in the terminal under a GUI session spawned for "someone". That's all a bit assumptive, but I believe I've done that...

Not terribly easy to automate.

D.E.R. Management - IT Project Management Consulting
 
You can also create menu items to gsudo the command, (is it gsudo? I know there is a ksudo, but not sure what gnomes is called)... Just copy the command as it is in each menu item you want to clone and create a new one with whatever the gnome graphical sudo is.

[plug=shameless]
[/plug]
 
MrCBofBCinTX said:
how do I add the "open as root" context menu item?
In GNOME? I have no idea. I know Nautilus has some kind of custom command/script feature, but being a KDE guy, I have absolutely no clue how it works.

In KDE, you would simply create a .desktop shortcut file for this action and drop it in ~/.kde/share/apps/konqueror/servicemenus/ or /usr/share/apps/konqueror/servicemenus/, depending on whether you want it per-user or system wide. When you right-click on a file of the appropriate MIME type, you will see the choice in the "Actions" menu.

As for the actual contents of the .desktop file, here's a shorter version of the "edit as root" service menu that comes with Kubuntu Edgy:
Code:
[Desktop Entry]
ServiceTypes=text/*,application/x-desktop
Actions=Editassu

[Desktop Action Editassu]
Name=Edit as Root
Icon=kfm
Exec=kdesu "kwrite" "%U"
The key lines to note are the Exec line, which is the command to execute, and the ServiceTypes line, which indicates what kind of files this is for. In this case, it is for all types of text files and for desktop shortcuts. KDE will only display the action if the file you right-click on is covered in this list of MIME types.

Hope that helps a little.
 
Haven't tried them yet but both of these sound very useful

found this at
Drag & Drop Sudo

This is a trick from the [WWW] forums
Create a launcher with the following command:

gksudo "gnome-open %u"

When you drag and drop any file on this launcher (it's useful to put it on the desktop or on a panel), it will be opened as root with its own associated application. This is helpful especially when you're editing config files owned by root, since they will be opened as read only by default with gedit, etc.


And I found this at
Most new Linux users just want to be able to click and drag and drop. So these two new commands should be your new best friends...

If you're using Ubuntu (Gnome), press Alt-F2 and type
gksudo nautilus

If you're using Kubuntu (KDE), press Alt-F2 and type
kdesu konqueror

If you're using Xubuntu (XFCE), press Alt-F2 and type
gksudo thunar

What do these commands do? They allow you to generally operate as a regular user but have a temporary window within your user account to operate as Root (just within the Nautilus or Konqueror window you've opened). Once you close the Root window, it's just as if you're a user again. You don't have to log out of user, log in as Root, make changes, log out of Root, and log back in as user again. You can be Root and user simultaneously.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top