1 安装树莓派系统
安装树莓派系统主要操作是烧录系统到 micro SD卡。
首先需要准备一张 micro SD 卡(一般16G)
格式化 SD 卡
若SD卡大于32G,SD Formatter会默认以exFAT的格式进行格式化,而Raspberry Pi目前的机型都还不支持对该格式的识别,因此才会无法识别大于32GB的卡
【解决办法】
将micro SD卡格式运用DiskGenius化成FAT格式就行。
更加强大的格式化工具 DiskGenius,


从树莓派官网下载 Raspberry Pi Imager


在 Operating System处选择系统,在 Storage 处选择要烧录到的SD卡。

点击 WRITE 等待烧录完成即可。
2 网络配置
有线网络配置
修改配置文件
sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf_backup
sudo vi /etc/dhcpcd.conf
末尾添加设置即可,其中192.168.128.100/24 ,24 代表 255.255.255.0
interface eth0
static ip_address=192.168.128.100/24
static routers=192.168.1.1
static domain_name_servers=202.102.152.3 114.114.114.114 8.8.8.8
无线网络配置
可根据开机提示直接连接,也可通过配置相关文件设置静态IP。
介绍将wifi设置为静态IP,修改文件/etc/network/interfaces
sudo cp /etc/network/interfaces /etc/network/interfaces_backup
sudo vi /etc/network/interfaces
将其中的wla0 无线端口进行修改,修改配置如下。
#allow-hotplug wlan0
#iface wlan0 inet manual
#wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
auto wlan0
iface wlan0 inet static
address 192.168.1.211
netmask 255.255.255.0
gateway 192.168.1.1
wpa-ssid C4
wpa-passphrase 1234567890
其中 wpa-ssid C4 为无线账号,C4
wpa-passphrase 1234567890 ,无线密码1234567890
3 换源
树莓派换源
sudo vi /etc/apt/sources.list
接着编辑这个文件,如下图所示,把原来的内容注释掉(最前面加 # 号),在文件最顶部添加下面的内容:

同样的方法,把 /etc/apt/sources.list.d/raspi.list 文件也替换成下面的内容:

4 ssh 与 vscode 远程
安装 ssh
树莓派端安装 ssh
sudo apt update
sudo apt apt install -y --no-install-recommends openssh-server
windows 端cmd连接
ssh pi@ip
输出,说明ssh可以连接:

vscode远程
树莓派端:
sudo vim /etc/ssh/sshd_config
修改下面几行
AuthenticationLoginGraceTime 120PermitRootLogin yesStrictModes yes
重启ssh
sudo service ssh start
判断ssh服务是否启动成功

设置ssh开启自动启动:
开机自动启动ssh命令sudo systemctl enable ssh
windows端vscode:
在设置面板中打开应用->可选功能->搜索 SSH,如下图所示,将两个都安装好。

vscode 安装 Remote Development 插件,此插件包括三个小插件分别是 Remote – WSL、Remote – Contaomers 和
Remote – SSH,我们用到的就是 Remote – SSH。

安装好 Remote Development 和 python 插件后在 vscode 左侧就有一个小电视机的图标,点击此图标后选择 SSH
Targets,之后点击小齿轮设置,选择设置搜索框中选中第一个,之后出现 SSH 远程设置界面,其中 Host 是指在 vscode
中远程连接的名字,Hostname 值的是宿主机下的 IP 地址,User 写pi即可,Port 是指 写 22 号端口
映射到宿主机下的端口。


启动远程连接:

之后选择 Linux,按照提示连接即可。
若vscode出现如下连接异常

则说明在 C:\Users\Admin/.ssh.known_hosts的第三行存在重复密钥,加载了原先的错误密钥,导致连接不上。
【解决办法】
清空 C:\Users\Admin/.ssh.known_hosts文件中内容重新连接即可。
原作者:JeremyJ