使Vim在远程编辑多个文件时保留密码

问题描述 投票:0回答:1

考虑您有一个工作站,将其连接到远程服务器并像在其中编辑一些文件一样

workstation $ ssh [email protected]     # Log into the remote server
Password: MyPassw0rd!
server $ ls  /home/sarah/recipes/       # Files you want to edit
applePie.txt    bananaCake.txt
server $ vi  /home/sarah/recipes/       # Open this directory and edit the files in it
...
:x
server $ logout                         # Log out and come back to the workstation

现在您想在自己的工作站上使用Vim / Neovim。

workstation $ vim scp://[email protected]://home/sarah/recipes/
[email protected]'s password: MyPassw0rd!

问题是,每次在此服务器上打开文件时,都必须再次输入相同的密码。当Vim / Neovim在同一远程服务器上编辑文件时,有什么方法可以使该SSH会话保持活动状态?

vim ssh remote-access neovim
1个回答
0
投票

Netrw,这是处理加载和保存远程文件的工具,仅提示输入FTP帐户的密码。您看到的提示实际上来自于scp,作为OpenSSH的一部分,它将仅提示您输入来自TTY的密码。

由于您直接在scp中输入密码,并且所调用的scp进程的运行时间并不短暂,因此无法缓存密码。即使Netrw确实提示您输入密码,scp也不提供非交互方式读取密码的方法,因此Netrw无法缓存它并继续传递密码。

如果您不想每次都输入密码,则需要使用SSH密钥。为了减轻设置负担,您可以使用ssh-copy-id一次将密钥复制到远程系统,然后在没有密码提示的情况下正常使用Vim。

© www.soinside.com 2019 - 2024. All rights reserved.