翻译修改自:https://codepen.io/ginfuru/post/remote-editing-files-with-ssh
在远程服务器上编写文件是一件很糟糕的事情,vim和其他终端编辑器,让速度和熟练度大打折扣,一整天使用vim和FTP客户端并不是一件舒心的事情。
所以,如果你已经知道 SSH 是什么以及涉及到什么,你可以完全访问你的服务器,你就无需害怕终端。
现在我们通过使用Visual Studio代码通过 SSH 远程编辑文件
步骤一:
安装扩展 `remote-vscode`
步骤二:
添加 RemoteForward 52698 127.0.0.1:52698 到 ~/.ssh/config:
Host myRemoteServerName
HostName 12.34.567.89
User root
ForwardAgent yes
RemoteForward 52698 127.0.0.1:52698
步骤三:
连接远程:
ssh -v myRemoteServerName
安装rmate:
wget -O /usr/local/bin/rcode https://raw.github.com/aurora/rmate/master/rmate &&chmod a+x /usr/local/bin/rcode
步骤四:
重新登陆远程, 运行
rcode some_file.php
或者
rmate some_file.php
文件就会出现在Visual Studio。
PS:
我在远程添加别名 .bashrc –> alias code='rcode' 这样我的本地和远程就可以用相同的命令从终端打开Visual Studio
如果报错 “no such file or directory” , 你需要编辑PATH:
echo "export PATH=\"$PATH:/usr/local/bin\"" >> /etc/profile