環境准備
- 本地操作系統使用win10 1809以上,這個版本自帶Open SSH Client,可以省去ssh的配置
- 遠程Linux主機打開SSH密鑰登錄設置:
PubkeyAuthentication yes
本地win10生成密鑰對
ssh-keygen -t rsa -b 4096 -f D:\DevEnv\conf\ssh\id_rsa-remote-ssh
遠程Linux主機配置
上傳生成的密鑰對(id_rsa-remote-ssh和id_rsa-remote-ssh.pub)到Linux的相應用戶下,執行:
ssh-copy-id -i id_rsa-remote-ssh.pub 192.168.0.8
也可以手工配置,但通過ssh-copy-id命令配置,可以為用戶主目錄(home)和~/.ssh, 和~/.ssh/authorized_keys設置合適的權限
完成后刪除id_rsa-remote-ssh和id_rsa-remote-ssh.pub
設置vscode的Remote - SSH插件配置文件:
Host 192.168.0.8
HostName 192.168.0.8
User ubuntu
IdentityFile D:\DevEnv\conf\ssh\id_rsa-remote-ssh