Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Main Support Categories > General Help
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Ubuntu 9.10 is out!!!

When downloading Ubuntu 9.10 please consider using bittorrent to get your copy of Ubuntu.

The Ubuntu Developers Summit for Lucid Lynx will be held the week of 16-Nov-2009 till 20-Nov-2009 in Dallas, TX USA. Visit the the Ubuntu wiki for more information about UDS and how to participate remotely.

General Help
All your general support questions for Ubuntu, Kubuntu, Edubuntu and Xubuntu.

 
Thread Tools Display Modes
Old May 3rd, 2008   #1
linuxed
A Carafe of Ubuntu
 
Join Date: May 2008
Beans: 83
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
linuxed is offline   Reply With Quote
Old May 3rd, 2008   #2
linuxed
A Carafe of Ubuntu
 
Join Date: May 2008
Beans: 83
Re: export EDITOR=gedit && sudo visudo opens the sudoers file in the terminal window

Any suggestions would be appreciated.
linuxed is offline   Reply With Quote
Old May 3rd, 2008   #3
prshah
Iced Blended Vanilla Crème Ubuntu
 
prshah's Avatar
 
Join Date: Oct 2007
Location: Chennai, India
Beans: 2,884
Ubuntu Karmic Koala (testing)
Send a message via Yahoo to prshah
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
Ubuntu, Kubuntu, Xubuntu, Mythbuntu All-in-One Live DVD
"I never make mistakes; I thought I did, once.. but I was wrong."
prshah is online now   Reply With Quote
Old May 3rd, 2008   #4
bollix47
Quad Shot of Ubuntu
 
Join Date: Apr 2006
Beans: 496
Ubuntu 8.04 Hardy Heron
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.
bollix47 is offline   Reply With Quote
Old May 3rd, 2008   #5
linuxed
A Carafe of Ubuntu
 
Join Date: May 2008
Beans: 83
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?
linuxed is offline   Reply With Quote
Old May 3rd, 2008   #6
tinivole
Should have gone to University
 
tinivole's Avatar
 
Join Date: Jan 2008
Location: UK
My beans are hidden!
Ubuntu 9.04 Jaunty Jackalope
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 tinivole; May 3rd, 2008 at 03:08 PM..
tinivole is offline   Reply With Quote
Old May 3rd, 2008   #7
linuxed
A Carafe of Ubuntu
 
Join Date: May 2008
Beans: 83
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 -.
linuxed is offline   Reply With Quote
Old May 3rd, 2008   #8
tinivole
Should have gone to University
 
tinivole's Avatar
 
Join Date: Jan 2008
Location: UK
My beans are hidden!
Ubuntu 9.04 Jaunty Jackalope
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 tinivole; May 3rd, 2008 at 03:19 PM..
tinivole is offline   Reply With Quote
Old May 3rd, 2008   #9
linuxed
A Carafe of Ubuntu
 
Join Date: May 2008
Beans: 83
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.
linuxed is offline   Reply With Quote
Old May 3rd, 2008   #10
p_quarles
Midnight Commander
 
p_quarles's Avatar
 
Join Date: May 2007
Beans: 7,043
Kubuntu 9.04 Jaunty Jackalope
Send a message via AIM to p_quarles
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!
p_quarles is offline   Reply With Quote

Bookmarks

Tags
sudoers

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:56 AM.


vBulletin ©2000 - 2009, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. lingonberry