LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-09-2009, 09:39 PM   #1
newbiesforever
Senior Member
 
Registered: Apr 2006
Location: Iowa
Distribution: Debian distro family
Posts: 2,378

Rep: Reputation: Disabled
can I edit sudoers without vi?


I want to add myself (the only user) to the sudoers file, but I haven't learned how to use vi, which the file says must be used to edit it. I don't suppose there's another way?
 
Old 11-09-2009, 10:02 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Unless visudo(8) was compiled specifically to use a different editor, vi is what it defaults to. (You should probably learn vi.)

If you're willing to forgo syntax checking, you can edit it with whatever you'd like, e.g.:
# nano /etc/sudoers

Just so I'm being clear: I would recommend the former approach.
 
Old 11-09-2009, 10:55 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
It is possible to edit the /etc/sudoers file directly, but visudo is recommended because it will check your changes for syntax errors before committing them.

But it's not necessary to do it directly, because visudo will obey either the VISUAL or EDITOR environmental variables if they exist (except in the unlikely event you have a version that wasn't compiled with such support). Just set one of these to the editor you want, and it should use that instead of vi. See the visudo man page for details.

(Many other programs use the EDITOR variable too, so I recommend you set it to your favorite text editor anyway.)
 
Old 11-09-2009, 10:57 PM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
You should use visudo. This will ensure correct file locking and syntax checking. By default, visudo will probably use the vim editor, but you can change that by setting the EDITOR variable.

For example if you want to use nano, run the following command

Code:
EDITOR=nano visudo
Cheers,

Evo2.
 
Old 11-09-2009, 11:13 PM   #5
j1alu
Member
 
Registered: Apr 2009
Distribution: debian gnu/linux
Posts: 798

Rep: Reputation: Disabled
for me, on debian, visudo uses nano out of the box
(which is very confusing for me: i hit an "i" or an "G" or an "$" and it prints it on the screen. wtf, where is the command mode?. lol). if its the same way on mepis i wouldnt know.

if you wanna learn vim install the full version:
Code:
apt-get install vim
which is a bit more comfortable, less confusing.

with the following you should be able to use the basics within a few days:
http://www.swaroopch.com/notes/Vim_en:Table_of_Contents

at least you only need two commands/shortcuts:
i to change from command mode and be able to insert text at the cursors position.
hit the esc button to get into command mode and x to save the changes and quit vi
(esc and q! to quit without saving the changes).
use the arrows to navigate for now.
(hit esc + then u deletes the last changes you made, which might be necessary now and then)
it might be better hitting the esc a few times, so you will for sure change the mode.

Last edited by j1alu; 11-10-2009 at 12:53 AM.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to edit "sudoers" file using visudo maniac matt Linux - Newbie 11 06-22-2013 08:38 AM
can I edit sudoers without vi? newbiesforever Linux - General 4 08-10-2009 01:35 PM
Edit sudoers by script snowman81 Programming 5 05-27-2008 06:52 PM
cannot edit /etc/sudoers unisol Ubuntu 13 06-18-2006 09:35 AM
visudo lets me edit sudoers but not save ver 3.3.1 suguru MEPIS 4 12-19-2005 06:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration