vscode使用ssh远程开发

  1. 生成了 SSH 密钥,将 SSH 密钥复制到~/.ssh文件夹中
mkdir -p ~/.ssh # 创建.ssh文件夹
chmod 700 ~/.ssh # 设置.ssh文件夹权限为700

2.将公钥添加到authorized_keys文件中

ssh-copy-id xxx@ip地址 #最简单

# 或者在远程服务器上,将公钥添加到authorized_keys文件中
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys 

# 设置authorized_keys文件权限为600
chmod 600 ~/.ssh/authorized_keys 

如果遇到错误:

NFO: Source of key(s) to be installed ......
ttempting to log in with the new key(s), to filter out any that are already installed.......

这是遇到的错误是 SSH 主机密钥变更警告(Host Key Verification Failed),这是 SSH 的安全机制在起作用,用于保护连接的安全性。 解决方法:

# 清除旧的主机密钥记录
ssh-keygen -f '/home/xxx/.ssh/known_hosts' -R 'ip地址'
# 然后重试 ssh-copy-id
ssh-copy-id -i ~/.ssh/id_rsa.pub xxx@xxx

完成!之后 SSH 和 VS Code Remote-SSH 都可免密登录