Wednesday, 13 June 2012

Run as root ubuntu 12.04

This might work on other versions of ubuntu and other Linux distributions.

  1. Create a place to keep the launcher. I have a folder in my UbuntuOne called launchers.
  2. create a file, lets call it "my_launcher" for this example. (I use vim, but gedit will work just as well.)
  3. write:
    [Desktop Entry]
    Version=1.0
    Type=Application
    Terminal=false
    Icon[en_GB]=etherape
    Name[en_GB]=etherape as root
    Exec=gksudo -k -u root etherape
    Name=etherape as root
    Icon=/usr/share/app-install/icons/etherape.png
    GenericName[en_GB]=EtherApe
  4. save it and change the permissions to 775 (rwxrwxr-x) which you can do on the command line, (if you are in the same directory as the new file), with:

     chmod 775 my_launcher

    or by right-clicking on the icon, at the bottom should be Properties and hidden in there will be permissions - just set them all except for Others: write (though you should try to learn about that and the scary implications before blindly following some random blog - Linux lets you do almost anything... including shooting yourself in the foot.)
  5. drag it to the launcher for easy access.
The magic line is:

Exec=gksudo -k -u root etherape
 
This runs, in this case, etherape as root, (that pesky Administrator in the Linux world.)

( If you have terminal already open then:

gnome-desktop-item-edit --create-new ~/Desktop

is also an option.)

Much of the reset of the entry can be changed or removed. Want to edit something as root?

#!/usr/bin/env xdg-open

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon=/usr/share/icons/Humanity/apps/16/gedit-icon.svg
Exec=gkedit -k -u root gedit
Name=gedit
 
and the amazing thing - this is just text, but you are now a programmer, (yeah maybe get some scripting language and compiled languages under your belt before adding programmer to your C.V.).

p.s. I have no idea why gedit needs xdg-open and etherape does not, but I'm sure someone in the comments knows...

No comments:

Post a Comment

About this blog

Sort of a test blog... until it isn't