用vim 透明编辑远程文件(scp协议)

------------------------------------------------------------
用vim 透明编辑远程文件(scp协议)
------------------------------------------------------------
请先确认你安装了netrwPlugin.vim 插件, 同时也要保证双机之间支持scp 协议(安装相关服务)
1. 先保证scp 是可以正常工作的, 例如, 要编辑192.168.1.136主机, /opt/ma.conf 文件,如下测试:
scp [email protected]:/opt/ma.conf .

root 是用户名,192.168.1.136是远程主机,:是用来分割主机与端口的,不写端口就是默认端口,后面是文件路径

可能会有如下警告! 则按提示执行删除命令即可, 再运行scp 要保证可以通过.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:SL7/fVrRgb6j/NUSRHojLZbN5rPbyo6YSPFfiLjegaI.
Please contact your system administrator.
Add correct host key in /home/hjj/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/hjj/.ssh/known_hosts:10
  remove with:
    ssh-keygen -f "/home/hjj/.ssh/known_hosts" -R "192.168.1.136"

2. 再使用vim 编辑远程文件(否则编不了文件你不知傲哪里出了问题)
书写格式稍微有些变化,如下示例:
vim scp://[email protected]//opt/ma.conf

scp:// scp 是协议, ://用来隔离协议与主机名.
主机名和路径之间也要用//来隔离, 第一个/用来隔离,第二个/是根的意思!

如此你便可以像编辑本地文件一样编辑(read-modify-write)一个远程文件了.

 

你可能感兴趣的:(vim&emacs)