安装 VSCode 及 Remote SSH 插件
-
安装插件:
Remote - SSH
生成 SSH 密钥对(如果没有的话)
打开 PowerShell 或 CMD:
ssh-keygen
默认会保存在:
C:\Users\你的用户名\.ssh\id_rsa(私钥) C:\Users\你的用户名\.ssh\id_rsa.pub(公钥)
直接按回车即可,不设密码。
登录树莓派并上传公钥
先用普通方式连接一次:
ssh [email protected] # 或 ssh [email protected]
然后在树莓派上执行:
mkdir -p ~/.ssh chmod 700 ~/.ssh
然后用如下命令将 Windows 上的公钥复制进去(在 Windows 端执行):
type $env:USERPROFILE\.ssh\id_rsa.pub | ssh [email protected] "cat >> ~/.ssh/authorized_keys"
再设置好权限(树莓派端):
chmod 600 ~/.ssh/authorized_keys
编辑 SSH 配置文件(Windows)
打开:
C:\Users\你的用户名\.ssh\config
(没有就创建)
添加如下内容:
Host rpi HostName 192.168.x.x # 树莓派的 IP User pi IdentityFile ~/.ssh/id_rsa