Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SudoWrite not working in neovim #56

Closed
eskinderg opened this issue Nov 12, 2018 · 7 comments
Closed

SudoWrite not working in neovim #56

eskinderg opened this issue Nov 12, 2018 · 7 comments

Comments

@eskinderg
Copy link

I have used the SudoWrite functionality and have saved me so much time.
Recently i am not sure why i am get the following message when i do the SudoWrite.

Error detected while processing BufWriteCmd Auto commands for "/etc/systemd/logind.conf":
sudo: no tty present and no askpass program specified

Below is my neovim version.
:version
NVIM v0.3.0
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

@randomizedthinking
Copy link

It is a known issue in neovim: neovim/neovim#8527. The conclusion is not-to-fix since the current vim approach can create other unpleasant problems too -- it is just trade-off.

You can use: https://github.com/lambdalisue/suda.vim. It would be nice if @tpope can incorporate it to vim-eunuch.

@tpope
Copy link
Owner

tpope commented Nov 18, 2018

Handling the password ourselves makes me a bit squeamish but I I can't think of a practical objection.

@rdnetto
Copy link

rdnetto commented Nov 19, 2018

EDIT: Meant to post this yesterday, but only realised after posting that I hadn't refreshed the page and that the conversation had continued while I wasn't paying attention.

This is caused by neovim/neovim#8217. https://github.com/lambdalisue/suda.vim demonstrates one workaround for it (explicitly reading the password with inputsecret() and piping it in with sudo --stdin), which suffers from a few weaknesses compared to vim-eunuch's current implementation (password is temporarily stored in Vim, password must be re-entered multiple times).

Another more secure, but less portable, workaround is to just use netrw to edit the file over SSH via root@localhost, assuming you have the daemon running and your public key in root's authorized_hosts file.

Ideally we'd have a simple executable which prompted for the password then disappeared into the background, but that's a lot of complexity for the increase in security gained from the not keeping the password in Vim.

At any rate, I'll leave it to people who know more than me about these things to decide.

@tpope
Copy link
Owner

tpope commented Nov 19, 2018

Oh, the re-entering of the password is a pretty huge compromise.

@Trollwut
Copy link

stupid question: so currently SudoWrite doesn't work in neovim?

@tpope
Copy link
Owner

tpope commented Feb 13, 2020

It works if you have $SUDO_ASKPASS set, or Path askpass configured in /etc/sudo.conf.

@TSFoster
Copy link

Leaving this here in case it is of any use to people using macOS + nvim. There might be better ways, but here is how I got it to work:

  1. Create file macos-askpass:

    #!/usr/bin/env osascript -l JavaScript
    
    var app = Application.currentApplication();
    app.includeStandardAdditions = true;
    app.displayDialog("Enter password:", { hiddenAnswer: true, defaultAnswer: "" }).textReturned;
  2. chmod +x /path/to/macos-askpass

  3. Set $SUDO_ASKPASS to /path/to/macos-askpass (I do this in my init.vim with let $SUDO_ASKPASS="/path/to/macos-askpass")

aktau added a commit to aktau/dotfiles that referenced this issue Jul 3, 2020
I mostly used it for :SudoWrite, but that doesn't work in Neovim (at the
moment): tpope/vim-eunuch#56.
currybullen added a commit to currybullen/dotfiles that referenced this issue Sep 4, 2021
:SudoWrite, perhaps along with other commands, do not work with neovim,
see tpope/vim-eunuch#56.
aljoschua added a commit to aljoschua/dotfiles that referenced this issue Oct 31, 2021
In the referenced Post, I realised that handling password saving inside
Vim is probably not a good idea. I'm not a security expert and Vim is
(probably?) not a hardened secure application. I really wanted to be
prompted through the terminal, but I guess a little graphical program is
fine..

See tpope/vim-eunuch#56 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants