vscode 远程开发连接ssh 密钥方式,避免每次都输入密码


参考:https://developer.aliyun.com/article/1599623
https://blog.csdn.net/jacke121/article/details/143928971

生成key

首先在你本地的的命令行中生成一个私钥(id_rsa)和一个公钥(id_rsa.pub)

输入以下代码,一路回车到最后即可

  1. ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

一般路径在~/.ssh/id_rsa~/.ssh/id_rsa.pub

将公钥部署在服务器上

找到~/.ssh/authorized_keys文件并编辑,将~/.ssh/id_rsa.pub内容复制另起一行追加到末尾

vscode本地配置

打开ssh配置文件(一般是~/.ssh/config),在配置块中添加 IdentityFile ~/.ssh/id_rsa

示例:

  1. Host esxi-GO-NODE-builder
  2. HostName 192.168.3.175
  3. User root
  4. IdentityFile ~/.ssh/id_rsa