今天試用了一下 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
以上僅只是入門介紹,可讓你快速的把這個插件用起來,更多高級功能,仍是建議你去閱讀官方文檔中的內容。
參考: