Results 1 to 10 of 12

Thread: export EDITOR=gedit && sudo visudo opens the sudoers file in the terminal window

Hybrid View

  1. #1
    Join Date
    May 2008
    Beans
    99

    export EDITOR=gedit && sudo visudo opens the sudoers file in the terminal window

    I need to edit my sudoers file but for some reason the sudoers file keeps opening in the terminal window instead of gedit. What am I doing wrong? I'm currently running Ubuntu 8.04.

    export EDITOR=gedit && sudo visudo

    At the moment the only way I can edit the file is to chmod it and then double click on the file icon. I can't even open gedit from the terminal as root. The following error is displayed when I type /usr/bin/gedit or gedit as root.

    cannot open display:
    Run '/usr/bin/gedit --help' to see a full list of available command line options

  2. #2
    Join Date
    May 2008
    Beans
    99

    Re: export EDITOR=gedit && sudo visudo opens the sudoers file in the terminal window

    Any suggestions would be appreciated.

  3. #3
    Join Date
    Apr 2006
    Beans
    511
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: export EDITOR=gedit && sudo visudo opens the sudoers file in the terminal window

    From man sudoers:

    Code:
    The sudoers file should always be edited by the visudo command
    which locks the file and does grammatical checking. It is imperative that 
    sudoers be free of syntax errors since sudo will not run with a syntactically 
    incorrect sudoers file.

  4. #4
    Join Date
    May 2008
    Beans
    99

    Re: export EDITOR=gedit && sudo visudo opens the sudoers file in the terminal window

    Thanks prshah. The -E fixed it. My only other question is how I can get gedit to open from the terminal as root. If I type su - , enter the root password, and then type gedit I'm still presented with an error stating that gedit can't open. However if I type gedit in the terminal from my standard user account it opens without any problems. Is there a line I can add to the sudoers file to fix this?

  5. #5
    Join Date
    Jan 2008
    Beans
    4,757

    Re: export EDITOR=gedit && sudo visudo opens the sudoers file in the terminal window

    [EDIT]
    Sorry, you mean to open visudo with gedit automatically?

    you can add some lines to the bottom of your .bashrc file to do that.

    Code:
    gedit ~/.bashrc
    And add to the bottom.
    PHP Code:
    export EDITOR=gedit
    alias visudo
    ='-E visudo' 
    That will fix it.

    All you now have to type in is:
    Code:
    sudo visudo
    Without worrying about anything else!

    Regards
    Iain
    Last edited by ibuclaw; May 3rd, 2008 at 08:08 PM.

  6. #6
    Join Date
    May 2008
    Beans
    99

    Re: export EDITOR=gedit && sudo visudo opens the sudoers file in the terminal window

    Perfect! I can now open gedit from the terminal as root using sudo -s. However I'm not prompted to enter a password when I use sudo -s. I'm only prompted to enter the root password with su -.

  7. #7
    Join Date
    Oct 2007
    Location
    Chennai, India
    Beans
    3,786
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: export EDITOR=gedit && sudo visudo opens the sudoers file in the terminal window

    Quote Originally Posted by linuxed View Post
    export EDITOR=gedit && sudo visudo
    When you set an environment variable, it is set only for the particular user, not for sudo (root).

    Try code:
    Code:
    export EDITOR=gedit && sudo -E visudo
    Where "-E" means "preserve environment".

    Alternatively, you can change the value of "editor" in the sudoers file.
    Cheers,PRShah
    Make your own: Ubuntu, Kubuntu, Xubuntu, Mythbuntu All-in-One Live DVD
    "I never make mistakes; I thought I did, once.. but I was wrong."

  8. #8
    Join Date
    May 2007
    Beans
    7,032
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: export EDITOR=gedit && sudo visudo opens the sudoers file in the terminal window

    Quote Originally Posted by prshah View Post
    Try code:
    Code:
    export EDITOR=gedit && sudo -E visudo
    Where "-E" means "preserve environment".
    Thanks for this, prshah. The need to use environment preservation with sudo is apparently need to Ubuntu 8.04. I'll try to incorporate this into a more permanently visible location, since there are dozens of tutorials on the web that explain how to export editors, but none that I have seen mention this.
    I am aware of all internet traditions. | Getting the best help | Text formatting codes | My last.fm profile
    Should I PM support questions? NO!

  9. #9
    Join Date
    Jan 2008
    Beans
    4,757

    Re: export EDITOR=gedit && sudo visudo opens the sudoers file in the terminal window

    Quote Originally Posted by p_quarles View Post
    Thanks for this, prshah. The need to use environment preservation with sudo is apparently need to Ubuntu 8.04. I'll try to incorporate this into a more permanently visible location, since there are dozens of tutorials on the web that explain how to export editors, but none that I have seen mention this.
    If you want a more permanent link. I made a bug about this when Hardy was in Alpha (I'd never used vi before and got quite a shock).

    But I think that my workaround is sound too.

    Regards
    Iain

  10. #10
    Join Date
    May 2007
    Beans
    7,032
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: export EDITOR=gedit && sudo visudo opens the sudoers file in the terminal window

    Quote Originally Posted by tinivole View Post
    If you want a more permanent link. I made a bug about this when Hardy was in Alpha (I'd never used vi before and got quite a shock).

    But I think that my workaround is sound too.

    Regards
    Iain
    I added it to the forum policy statement in Security Discussions, which is a sticky thread.

    And, yes, your workaround is good, but it's just a more permanent version of the same thing. The -E option is the key to both.
    I am aware of all internet traditions. | Getting the best help | Text formatting codes | My last.fm profile
    Should I PM support questions? NO!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •