Page 1 of 2 12 LastLast
Results 1 to 10 of 12

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

  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
    Oct 2007
    Location
    Chennai, India
    Beans
    3,804
    Distro
    Ubuntu Development Release

    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."

  4. #4
    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.

  5. #5
    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?

  6. #6
    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.

  7. #7
    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 -.

  8. #8
    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 linuxed View Post
    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 -.
    If you have used the sudo command. Sudo will remember that you've used it, so you can do other sudo commands without being prompted for a password.

    To change this (ie: to be prompted for a password everytime):
    open up visudo.
    Then type in:
    Code:
    Defaults:ALL    timestamp_timeout=0
    Put it at the bottom of the file.

    Or if every time you use sudo is a bit excessive (ie: "sudo apt-get update && sudo apt-get upgrade && sudo apt-get clean" asks you three times in one sitting.)

    You can change the timeout=0 to timeout=1 or 2. The value stands for the number of minutes before it asks you again.
    I think the default is 15 minutes, or until the shell is closed.

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

  9. #9
    Join Date
    May 2008
    Beans
    99

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

    Many thanks. That fixed it and I'm now prompted for the password each time.

  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 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!

Page 1 of 2 12 LastLast

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
  •