Neovim scp doesn't prompt for password - vim

In Vim, this prompts me for a password allowing me to edit a remote file:
:e scp://username#host//path
Yet, using the same command with NeoVim doesn't prompt for a password because the underlying command :! scp user#host:path LOCAL-TEMPFILE does not work interactively in NeoVim: https://github.com/neovim/neovim/wiki/FAQ#-and-system-do-weird-things-with-interactive-processes
What is the best practice to edit a remote file with NeoVim that has password authentication over ssh?

I would guess that the netrw plugin that provides this functionality isn't installed / active for Neovim. Check whether the :Nread command is available. Compare the :scriptnames output from Vim and Neovim. Read the plugin's documentation :help pi_netrw for how to install and enable it.
Update: So, it turns out that there's an Neovim issue with interactive commands started from :!, and this is what netrw is doing; the plugin does not capture the password challenge. It's basically executing :! scp user#host:path LOCAL-TEMPFILE
If you can avoid the issue (use key-based SSH authentication for the hosts), you could continue to use Neovim with netrw. If this is really important to you, more elaborate workarounds are possible. (For example, I use a wrapper around ssh that parses ~/.ssh/config for custom Password Hunter2 entries (these passwords are well known in the org and only used for testing VMs, so no security issue here), and then uses sshpass to automatically log in.)
Else, you have to switch to classic Vim for netrw operations, or use another way of accessing these remote files (e.g. SSHFS).

Related

What happens when I execute vim remotely over ssh? [duplicate]

I have a remote file that I edit regularly. I would like to edit it with a quick, simple command that would work likely via SSH. At present, my workflow is to connect to the remote computer via SSH, open the file using an editor (say vim or nano), edit, save and then close the connection.
I am aware that I can mount the remote computer filesystem using SSHFS or Nautilus capabilities, but I'm really looking for a single command to run in the terminal which shall open the file in an editor, allow me to save and then exit, closing all connections to the remote computer.
Currently, I am trying to do this by passing a command to the remote computer via SSH, but I am running into difficulties. For VIM, the command is something like the following:
ssh user1#computer1 "vim /path/laboratory_notebook_1.md"
Using this procedure, VIM does not run correctly and presents the following error:
Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal
For nano, the command is something like the following:
ssh user1#computer1 "nano /path/laboratory_notebook_1.md"
Using this procedure, nano does not run and the following error is presented:
Error opening terminal: unknown.
I'm not sure how to proceed on this line of thought. I would appreciate assistance on this method and suggestions on other ways to edit remote files briskly with a minimum amount of interaction.
Force Pseudo-TTY Allocation
You can force pseudo-tty allocation with one or more -t flags. The SSH(1) man page says:
-t Force pseudo-tty allocation. This can be used to execute arbi-
trary screen-based programs on a remote machine, which can be
very useful, e.g. when implementing menu services. Multiple -t
options force tty allocation, even if ssh has no local tty.
Example
Using your own example, slightly modified, the following would work if you have a local TTY or PTY:
ssh -t user1#computer1 'vim /path/laboratory_notebook_1.md'
It works fine for me with OpenSSH_6.2p2. Your mileage (and operating environment) may vary.
If you are using vim. Vim comes with a plugin called netrw which will allow you to do this.
vim scp://hostname/path/to/file
Will copy the file to you local machine and on save reupload it.
Take a look at netrw's documentation :h netrw

How do I write a script to open a pgp file with gvim?

I have a pgp encrypted text file that needs to be read by someone who is not comfortable with vim or the command line, though I think gvim will work for their needs. I edit the file using vim and the gnupg.vim plugin. According to the gnupg.vim documentation:
In some cases gvim can't decrypt files
This is caused by the fact that a running gvim has no TTY and thus gpg is
not able to ask for the passphrase by itself. This is a problem for Windows
and Linux versions of gvim and could not be solved unless a "terminal
emulation" is implemented for gvim. To circumvent this you have to use any
combination of gpg-agent and a graphical pinentry program:
- gpg-agent only:
you need to provide the passphrase for the needed key to gpg-agent
in a terminal before you open files with gvim which require this key.
- pinentry only:
you will get a popup window every time you open a file that needs to
be decrypted.
- gpgagent and pinentry:
you will get a popup window the first time you open a file that
needs to be decrypted.
I have pinentry-gnome3 installed on my machine, but it doesn't seem to work when I use vim or gvim, at least no gui pops up to request the password. When I try opening my pgp file with gvim I simply get an error telling me that the file could not be unencrypted.
The pinentry and gpg-agent man pages both indicate that they are called by other scripts and not manually. So, I am not sure how to get gvim to use them when trying to open my pgp file, especially in a script that can be called by users unfamiliar with the command line.
Try this (pgp.exe is from 1996)
c:> pgp -z"passphrase" -c file.pgp

How to make Vim open in a terminal instead of XQuartz when logged onto a remote server?

When I'm on my own computer's terminal, when I enter the command vim filename and vim opens the file in the terminal.
When I log into my school account using SSH, and I enter vim filename, nothing happens.
I assume it's trying to open it using XQuartz, which I recently uninstalled.
How do I make it open in the terminal window, like on my own computer?
I have tried not using -Y when logging on, but it doesn't make a difference.
Actually, there is a workaround. You can try to edit it using the scp option in Vim.
Just run vim scp://user#schoolserver.edu/path/to/your/file from your terminal and you'll start editing the file using Vim from your local machine.
If you want to learn more about scp in Vim type :help scp in Vim.

What is a quick way to edit a remote file on Linux?

I have a remote file that I edit regularly. I would like to edit it with a quick, simple command that would work likely via SSH. At present, my workflow is to connect to the remote computer via SSH, open the file using an editor (say vim or nano), edit, save and then close the connection.
I am aware that I can mount the remote computer filesystem using SSHFS or Nautilus capabilities, but I'm really looking for a single command to run in the terminal which shall open the file in an editor, allow me to save and then exit, closing all connections to the remote computer.
Currently, I am trying to do this by passing a command to the remote computer via SSH, but I am running into difficulties. For VIM, the command is something like the following:
ssh user1#computer1 "vim /path/laboratory_notebook_1.md"
Using this procedure, VIM does not run correctly and presents the following error:
Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal
For nano, the command is something like the following:
ssh user1#computer1 "nano /path/laboratory_notebook_1.md"
Using this procedure, nano does not run and the following error is presented:
Error opening terminal: unknown.
I'm not sure how to proceed on this line of thought. I would appreciate assistance on this method and suggestions on other ways to edit remote files briskly with a minimum amount of interaction.
Force Pseudo-TTY Allocation
You can force pseudo-tty allocation with one or more -t flags. The SSH(1) man page says:
-t Force pseudo-tty allocation. This can be used to execute arbi-
trary screen-based programs on a remote machine, which can be
very useful, e.g. when implementing menu services. Multiple -t
options force tty allocation, even if ssh has no local tty.
Example
Using your own example, slightly modified, the following would work if you have a local TTY or PTY:
ssh -t user1#computer1 'vim /path/laboratory_notebook_1.md'
It works fine for me with OpenSSH_6.2p2. Your mileage (and operating environment) may vary.
If you are using vim. Vim comes with a plugin called netrw which will allow you to do this.
vim scp://hostname/path/to/file
Will copy the file to you local machine and on save reupload it.
Take a look at netrw's documentation :h netrw

Custom autocompletion for zsh

ZSH has builtin autocompletion for scp, so a command like
scp user#host/path/
would show directory listings on the remote server.
However, this does not work when opening a remote file in vim
vim scp://user#host/path/
I have googled around for documentation on the zsh autocomplete functions but it seems very complicated. How can I enable autocomplete for vim scp?
Complete autocompletion documentation is located in man zshall (if you don't want to view all sections in one man, see index in man zsh). Completion for vim is located in /usr/share/zsh/$ZSH_VERSION/functions/Completion/Unix/_vim, I guess you need to modify _vim_files function located at the top of the file and somehow export function _remote_files located in the /usr/share/zsh/$ZSH_VERSION/functions/Completion/Unix/_ssh.

Resources