今天试用了一下 VSCode 的新插件:远程开发插件,体验很不错,它能够:bash
本文将以 SSH 链接的方式,作一个入门介绍,更多高级功能还需你在使用过程当中慢慢发掘。dom
Remote - SSH
插件,点击安装使用 ssh-keygen
工具在本机建立 ssh 秘钥,建立时一路回车便可 (注意:Remote-SSH 插件不支持输入帐号密码的链接方式,首选的登陆方式为使用非对称秘钥登陆)ssh
$ ssh-keygen
Enter file in which to save the key (/Users/fengyajie/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/fengyajie/.ssh/id_rsa.
Your public key has been saved in /Users/fengyajie/.ssh/id_rsa.pub.
The key fingerprint is:
The key's randomart image is: +---[RSA 2048]----+ | .oo*++.+o++| | +o Oo+ + +| | . . o+ o o | |.. o . +o . | |o o o . S+ | |.o . . . | |+.E . .. | |o=.+ . . .. | |.=*.. .. | +----[SHA256]-----+ 复制代码
将产生好的公钥发送到远端(使用 ssh-copy-id
工具),你须要将下面的 user@your_remote_host
修改成你开发机的用户名和主机名ide
$ ssh-copy-id -i ~/.ssh/id_rsa.pub user@your_remote_host
usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/fengyajie/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'user@your_remote_host'"
and check to make sure that only the key(s) you wanted were added.
复制代码
试一下链接,正常状况下你如今就能够直接登陆到远端机器了工具
$ ssh 'user@your_remote_host'
Welcome to Alibaba Cloud Elastic Compute Service !
Last login: Thu Jun 6 20:32:13 2019 from $local_ip
root@iZwz946zuZ:~#
复制代码
上面配置完成后,你就可使用 VSCode 链接到远端机器了,打开 VSCode,敲入 F1
键,输入 Remote-SSH:Connect to Host
,回车ui
接着输入你刚才配置好的 user@your_remote_host
,回车spa
此时 VSCode 会打开一个新的窗口,在这个窗口的左下角,你会观察到一个绿色的 SSH 状态条,表示此时你的 VSCode 已经连上了远程的开发机,以下插件
接下来,你就能够打开左上角的文件管理侧边栏,点击 Open Folder
,此时你会惊讶的发现,远端的 home
目录被列出来了:调试
至此,你已经在本地开启了一个「远端开发环境」,接下来你的开发任务不再受远程环境的限制了,能有这样的体验,仍是要感谢一下微软公司的贡献,真的是一款良心之做。code
以上仅只是入门介绍,可让你快速的把这个插件用起来,更多高级功能,仍是建议你去阅读官方文档中的内容。
参考: