You are not logged in.

#1 2010-05-26 19:35:20

gladstone
Member
Registered: 2009-01-03
Posts: 74

visudo does not respect VISUAL or EDITOR

I don't have vi installed (but do have vim) and since visudo uses vi as the default editor, I've set both VISUAL and EDITOR in .bashrc (as per the manual).

$ echo $EDITOR $VISUAL
vim vim

However, visudo still complains that vi isn't installed:

$ sudo visudo
visudo: no editor found (editor path = /usr/bin/vi)

Naturally, I'm running visudo with sudo... would that cause the issue or is this a bug?

Offline

#2 2010-05-26 19:40:11

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: visudo does not respect VISUAL or EDITOR

Have you tried to set EDITOR also in .bashrc of root?

Maybe that helps.

Regards

Offline

#3 2010-05-26 19:44:12

gladstone
Member
Registered: 2009-01-03
Posts: 74

Re: visudo does not respect VISUAL or EDITOR

Yeah, I tried that:

$ sudo cat /root/.bashrc
EDITOR="vim"
VISUAL="vim"

Offline

#4 2010-05-26 20:05:12

thestinger
Package Maintainer (PM)
From: Toronto, Canada
Registered: 2010-01-23
Posts: 478

Re: visudo does not respect VISUAL or EDITOR

ln -s /usr/bin/vim /usr/bin/vi

will fix the problem, but it isn't really a clean solution (maybe make a pkgbuild for vi that's just a symlink?)

Offline

#5 2010-05-26 20:06:35

scio
Member
From: Buffalo, NY
Registered: 2008-08-05
Posts: 366

Re: visudo does not respect VISUAL or EDITOR

Did you try

man visudo

it says that it does not respect EDITOR or VISUAL.  There are ways around it however.

Offline

#6 2010-05-26 20:14:40

rulex
Member
From: Finland
Registered: 2009-05-20
Posts: 55

Re: visudo does not respect VISUAL or EDITOR

isnt it:
export EDITOR="vim"

Offline

#7 2010-05-26 20:23:09

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: visudo does not respect VISUAL or EDITOR

i just added

# Defaults specification
Defaults editor=/usr/bin/vim

and that worked for me.

Offline

#8 2010-05-26 20:28:14

Square
Member
Registered: 2008-06-11
Posts: 435

Re: visudo does not respect VISUAL or EDITOR

sudo EDITOR=vim visudo

tongue

Also, exporting the EDITOR variable in root's account would probably set the editor correctly for when you sudo visudo, but I'm just guessing atm.

Last edited by Square (2010-05-26 20:29:00)


 

Offline

#9 2010-05-26 20:37:14

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: visudo does not respect VISUAL or EDITOR

@brisbin,

where did you add this? In your bashrc?

Regards

Offline

#10 2010-05-26 20:44:19

gladstone
Member
Registered: 2009-01-03
Posts: 74

Re: visudo does not respect VISUAL or EDITOR

@scio: really?

man visudo wrote:

ENVIRONMENT
       The following environment variables may be consulted depending on the value of
       the editor and env_editor sudoers variables:

       VISUAL          Invoked by visudo as the editor to use

       EDITOR          Used by visudo if VISUAL is not set

@brisbin33: Yeah, that works. Maybe it should be set as default in Arch? Though I recall reading there maybe some security risks involved...
@Square: bingo! that's my preferred method (though, no, it doesn't work if you set it in roots .bashrc (if that's what you mean))?

orschiro wrote:

@brisbin,

where did you add this? In your bashrc?

Regards

That goes in /etc/sudoers

Offline

#11 2010-05-26 20:46:39

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: visudo does not respect VISUAL or EDITOR

@gladstone. Thanks for this note.

Regards

Offline

#12 2010-05-26 20:48:11

gladstone
Member
Registered: 2009-01-03
Posts: 74

Re: visudo does not respect VISUAL or EDITOR

I just noticed this old bug report. Since vi is no longer symlinked to vim by default (correct me if I'm wrong and that never was the case), perhaps visudo should be built with "--with-editor=/usr/bin/vim"?

Offline

#13 2010-05-26 21:56:24

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: visudo does not respect VISUAL or EDITOR

gladstone wrote:

@brisbin33: Yeah, that works. Maybe it should be set as default in Arch? Though I recall reading there maybe some security risks involved...

man visudo wrote:

There is no easy way to prevent a user from gaining a root shell if the editor used by visudo allows shell escapes.

maybe this is the risk in using vim?

Offline

#14 2010-05-27 11:44:58

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: visudo does not respect VISUAL or EDITOR

# Defaults specification
Defaults editor=/usr/bin/vim

I tried that out but he still complains to need vi. Could this be a problem due to the bug report gladstone posted above?

Regards

Offline

#15 2010-05-27 11:49:58

Wintervenom
Member
Registered: 2008-08-20
Posts: 1,011

Re: visudo does not respect VISUAL or EDITOR

Defaults env_editor is the key.
Set your Sudo-user's $EDITOR environment variable to the binary of your favorite text-editor.

Last edited by Wintervenom (2010-05-27 11:50:53)

Offline

#16 2010-05-27 11:54:00

lymphatik
Member
From: Somewhere else
Registered: 2009-03-07
Posts: 119

Re: visudo does not respect VISUAL or EDITOR

orschiro wrote:

# Defaults specification
Defaults editor=/usr/bin/vim

I tried that out but he still complains to need vi. Could this be a problem due to the bug report gladstone posted above?

Regards

By adding /usr/bin/vim to Defaults it works perfectly however you have a security risk as vim can execute command in root. So you should add noexec for vim. Have a look at the manpage of sudoers for help. Look for preventing shell escape.

Offline

#17 2010-05-27 12:31:49

scio
Member
From: Buffalo, NY
Registered: 2008-08-05
Posts: 366

Re: visudo does not respect VISUAL or EDITOR

gladstone wrote:

@scio: really?

man visudo wrote:

ENVIRONMENT
       The following environment variables may be consulted depending on the value of
       the editor and env_editor sudoers variables:

       VISUAL          Invoked by visudo as the editor to use

       EDITOR          Used by visudo if VISUAL is not set

Yes, really.  Just like brisbin33 said, you need to add either editor or env_editor to your sudoers file.

gladstone wrote:

I just noticed this old bug report. Since vi is no longer symlinked to vim by default (correct me if I'm wrong and that never was the case), perhaps visudo should be built with "--with-editor=/usr/bin/vim"?

I would disagree since vim is in [extra] and vi is in [core].

Offline

#18 2023-02-08 03:13:59

ThinkPad
Member
Registered: 2019-01-29
Posts: 125

Re: visudo does not respect VISUAL or EDITOR

What fixed it for me was removing the conflicting global EDITOR definition I had in /etc/environment.

Offline

#19 2023-02-08 07:34:55

seth
Member
Registered: 2012-09-03
Posts: 59,761

Re: visudo does not respect VISUAL or EDITOR

So you necrobumped a 13 year old thread to let everyone know that you misconfigured your system…

Online

#20 2023-02-08 09:02:33

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 23,430

Re: visudo does not respect VISUAL or EDITOR

Offline

Board footer

Powered by FluxBB