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
Re: export EDITOR=gedit && sudo visudo opens the sudoers file in the terminal window
Any suggestions would be appreciated.
Re: export EDITOR=gedit && sudo visudo opens the sudoers file in the terminal window
Quote:
Originally Posted by
linuxed
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.
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.
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?
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.
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:
Without worrying about anything else!
Regards
Iain
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 -.
Re: export EDITOR=gedit && sudo visudo opens the sudoers file in the terminal window
Quote:
Originally Posted by
linuxed
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
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.
Re: export EDITOR=gedit && sudo visudo opens the sudoers file in the terminal window
Quote:
Originally Posted by
prshah
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.