一勾徽、本地安裝SSH客戶端
因為Windows沒有自帶的客戶端,所有這里采用openssh统扳。(也可以使用git
包含的ssh捂蕴,這里就不進行介紹了。)
- 以管理員方式運行啟動 Windows Powershell闪幽,依次粘貼如下兩條命令:
> Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
> Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
- 返回結(jié)果如下啥辨,證明成功:
Path :
Online : True
RestartNeeded : False
或命令行中輸入ssh
命令驗證:
[input]: ssh
[out]: usage: ssh [-46sdasdsfsf] [-B bind_interface]
[-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
[-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]
[-i identity_file] [-J [user@]host[:port]] [-L address]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-Q query_option] [-R address] [-S ctl_path] [-W host:port]
[-w local_tun[:remote_tun]] destination [command]
二、生成ssh-key
打開cmd盯腌,進入.ssh
目錄溉知,輸入以下命令:
> ssh-keygen -t rsa -b 4096
會提示輸入路徑文件名和密碼,這里假定文件名是id_rsa
腕够。
三级乍、上傳ssh-key公鑰到遠程服務(wù)器并配置
- 使用
scp
命令:
> scp -P [Port] [local .ssh file path]\.ssh\id_rsa.pub username@ip_adress_of_remote_server:~/.ssh/
這里要求遠程服務(wù)器上已有.ssh文件夾,沒有就提前創(chuàng)建一個帚湘。
- 將公鑰加入authorized_keys文件:
> ssh -p [port] username@ip_adress_of_remote_server #ssh連接遠程服務(wù)器
> cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys #公鑰加入authorized_keys文件
四玫荣、配置vscode
- 啟動vscode,在插件市場中搜索 remote development 并安裝大诸。
- 在vscode中編輯本地.ssh文件夾里的
config
文件捅厂,進入方法ctrl+shift+p
->Remote-SSH:Connect to host
->Configure SSH hosts
。
Host Server
HostName [ip_adress_of_remote_server]
User [username]
Port [port]
IdentityFile [local_ssh_file_path]\.ssh\id_rsa
#中括號內(nèi)為根據(jù)自己的配置實際填寫的內(nèi)容资柔,不需要中括號
-
設(shè)置完成后在遠程菜單內(nèi)即可看到設(shè)置的Host焙贷。
可雙擊或右鍵Host進行連接。