• Welcome to LiuJason's Blog!

没有显示器|鼠标|键盘Headless配置树莓派RaspberryPi的网络/WiFi/SSH

未分类 Jason 4 years ago (2020-03-16) 892 Views 0 Comments QR code of this page
文章目录[隐藏]

前言

Amazon.com上买了个树莓派4B 4G版 外壳,和一个手机支架一起凑赞加在一起107刀,比在Amazon.de上便宜了不少。等了将近半个月终于送到了,但是正好赶上nCov-19欧洲爆发了,家里没有可用的显示器和线....
还好树莓派本身就支持Headless配置,因此不用担心不能配置,跟着操作之后一样可以跑起来~
plug in the pi

准备工作

  • 树莓派1个(我这里是4B 4G版本,其他也一样)
  • 带读卡器的电脑一台(我这里是Mac,其他系统也一样)
  • MicroSD(TF)卡一张(推荐8G以上版本,点这里查看树莓派TF卡性能实测与选择
  • WiFi网络

给TF卡刷Raspbian系统

Raspbian是一款基于Debian Linux的树莓派专用系统,适用于树莓派所有的型号。除此之外,树莓派还支持许多操作系统:

  • Ubuntu,Ubuntu是基于Debian Linux 的桌面操作系统,树莓派分别支持Ubuntu META和Snappy Ubuntu Core两个版本,前者是桌面版,后者是面向开发者的桌面版。
  • OSMC,即开源媒体中心,是基于Linux内核的专门用于单板机的开源媒体播放器操作系统。
  • Windows 10 IoT Core,微软专为物联网开发打造的系统,Windows用户把玩树莓派的福音。
  • LibreELEC,轻量级Linux发行版,为嵌入式设备构建多媒体服务平台而设计。

官方推荐的Raspbian,也是我们这里要刷的系统,至少这个系统是完全支持Headless的。

操作步骤

1. 点击这里下载安装工具:Raspberry Pi Imager,记得选择自己合适的操作系统版本。

2. 插入TF卡到电脑中
3. 打开RaspberryPiImager,选择Radpbian和对应的TF卡设备
Raspberry Pi Imager in windows
Raspberry Pi Imager in windows
4. 点击Write开始刷入系统
Raspberry Pi Imager in windows
5. 完成
Write successful message

设置网络/SSH

一般如果有显示器和键盘的话,把TF卡直接插上树莓派然后通电就能用了,但是我并没有这些设备,所以需要直接修改配置文件让树莓派能够开机后连上WiFi并开启SSH让我们访问。

设置网络(WiFi)

打开TF卡的boot目录,新建一个文件wpa_supplicant.conf,内容如下:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<Insert country code here>

network={
 ssid="<WiFi的SSID>"
 psk="<WiFi的密码>"
}

开启SSH

树莓派系统非常人性化的加入了SSH自动部署功能,只要在boot目录下新建一个文件命名为SSH即可。

于是我们boot目录下有这两个新增的文件了:

最后就是获取设备的内网IP了,这个自己登录路由器就能看到(如果运营商良心的话,同时还有IPv6的公网):

测试连接

Jasons-MacBook-Pro ~ % ssh [email protected]
The authenticity of host '192.168.0.233 (192.168.0.233)' can't be established.
ECDSA key fingerprint is SHA256:7PVA5aerRTNNYCTIjhJdBzQWQKTPEsoime71dEAjS+k.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.233' (ECDSA) to the list of known hosts.
[email protected]'s password: 
Linux raspberrypi 4.19.97-v7l+ #1294 SMP Thu Jan 30 13:21:14 GMT 2020 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu Feb 13 16:17:10 2020

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.

pi@raspberrypi:~ $ 


This article is under CC BY-NC-SA 4.0 license.
Please quote the original link:https://www.liujason.com/article/644.html
Like (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址