xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

How to use SSH to access the Raspberry Pi without know the Wi-Fi IP address All In One

How to use SSH to access the Raspberry Pi without know the Wi-Fi IP address All In One

如何在不知道 Wi-Fi IP 地址的情况下使用 SSH 访问树莓派

没有显示器,不知道树莓派 IP 地址的情况下,如何通过 SSH 远程访问树莓派的终极解决方案

1. 必备条件

  1. 有一个家庭 Wi-Fi,有互联网访问; (PS: 也可以没有互联网访问, 如果有离线的系统镜像和 Raspberry Pi Imager 工具)
  2. SD 卡读卡器; (PS: 也可以没有, 如果电脑自带了读卡器)
  3. 一个 5V/3A 的 USB 电源适配器
  4. 一个树莓派 (3B / 3B+ / 4B)等
  5. 一台电脑

2. 前置条件

  1. 准备一个新的 SD 内存卡,选择 8GB ~ 256 GB, 推荐 32GB / 64GB, 太大一般也用不了
  2. 下载并安装Raspberry Pi Imager 工具
  3. 下载一个 64 位 Raspberry Pi OS 离线镜像,如果你网速快也可选择在线下载
# rpi-imager
$ sudo apt install rpi-imager

https://downloads.raspberrypi.org/imager/imager_latest.dmg

3. 操作步骤

安装 Headless Raspberry Pi 模式

  1. 选择 SD 卡, 使用 Raspberry Pi Imager 先格式化 SD 卡,然后选择一个要安装的系统(离线/在线)
  2. 选择安装系统后,点击右下角的 Advanced options 高级选项菜单
  3. 镜像自定义选项,选择 to always use 总是如此
  4. 配置主机名为默认的 raspberrypi.local,当然也可以自定义,没必要也不好记住
  5. 开启 SSH,选择使用密码授权
  6. 配置用户名pi与密码raspberry
  7. 配置无线网Wi-Fi 名称与密码,国家选择 CN
  8. 配置本地化,时区选择 Asia/Shanghai, 键盘布局选择 us 美式
  9. 永久性设置,默认全部选择即可
  • play sound 播放声音
  • eject media 退出媒体
  • telemetry 遥测/远程控制

4. 图解教程

描述
截图
格式化 SD 卡 image
步骤 1 ~ 6 image
步骤 6 ~ 7 image
步骤 7 ~ 8 image

https://www.raspberrypi.com/documentation/computers/getting-started.html

https://www.raspberrypi.com/documentation/computers/getting-started.html#sd-cards

https://www.raspberrypi.com/documentation/computers/getting-started.html#advanced-options

Headless Raspberry Pi

If you do not use a monitor or keyboard to run your Raspberry Pi (known as headless), but you still need to do some wireless setup, there is a facility to enable wireless networking and SSH when creating an image.

如果您不使用显示器或键盘来运行您的 Raspberry Pi(称为无头),但您仍需要进行一些无线设置,则可以使用一种工具在创建映像时启用无线网络和 SSH。


# SSH 连接 Raspberry Pi 无需通过 ip 地址访问,只需要使用默认的`用户名@主机名`即可 🚀
$ ssh pi@raspberrypi.local
$ ping raspberrypi.local

# 否则,SSH 连接 Raspberry Pi 就需要使用分配的 ip 地址访问
$ ssh pi@192.168.18.135

static ip address: 192.168.18.135

image

https://www.raspberrypi.com/documentation/computers/configuration.html#setting-up-a-headless-raspberry-pi

??? SSH 关闭了

image

wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<Insert 2 letter ISO 3166-1 country code here>

network={
        scan_ssid=1
        ssid="<Name of your wireless LAN>"
        psk="<Password for your wireless LAN>"
        proto=RSN
        key_mgmt=WPA-PSK
        pairwise=CCMP
        auth_alg=OPEN
}

https://www.raspberrypi.com/documentation/computers/configuration.html#configuring-networking-2

userconf.txt

Configuring a User You will need to add a userconf.txt in the boot partition of the SD card;

配置用户 你需要在 SD卡的引导分区中添加一个userconf.txt

# username:password
pi:raspberry

$ openssl passwd -6

https://www.raspberrypi.com/documentation/computers/configuration.html#configuring-a-user

或者,使用 Raspberry Pi Imager 工具右下角的 Advanced options 高级选项菜单配置

https://www.raspberrypi.com/documentation/computers/configuration.html#setting-up-a-headless-raspberry-pi

配置网络

https://www.raspberrypi.com/documentation/computers/configuration.html#configuring-networking

Command Line

$ sudo raspi-config

$ sudo iwlist wlan0 scan

$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
$ sudo vim /etc/wpa_supplicant/wpa_supplicant.conf
network={
  ssid="testing"
  #psk="testingPassword"
  psk=131e1e221f6e06e3911a2d11ff2fac9182665c004de85300f9cac208a6a80531
}
network={
    ssid="HomeOneSSID"
    psk="passwordOne"
    priority=1
    id_str="homeOne"
}

network={
    ssid="HomeTwoSSID"
    psk="passwordTwo"
    priority=2
    id_str="homeTwo"
}

DHCP Daemon

dhcpcd

Static IP Addresses

etc/dhcpcd.conf

interface eth0
static ip_address=192.168.0.4/24
static routers=192.168.0.254
static domain_name_servers=192.168.0.254 8.8.8.8

https://www.raspberrypi.com/documentation/computers/configuration.html#static-ip-addresses

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

Raspberry Pi Documentation

https://www.raspberrypi.com/documentation/

config.txt

https://www.raspberrypi.com/documentation/computers/config_txt.html

raspi-config

$ sudo raspi-config

https://www.raspberrypi.com/documentation/computers/configuration.html#raspi-config

https://www.raspberrypi.com/documentation/computers/configuration.html#the-boot-folder

raspi-config

# GUI 交互式命令行界面
$ sudo raspi-config

在本质上还是直接修改 /boot/config.txt 配置文件

https://www.raspberrypi.com/documentation/computers/configuration.html#the-raspi-config-tool

refs

https://www.cnblogs.com/xgqfrms/p/17300085.html#5166108

如何解决树莓派开机后无法获取到 Wi-Fi IP 问题 All In One

https://www.cnblogs.com/xgqfrms/p/17278676.html



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2023-04-15 23:21  xgqfrms  阅读(45)  评论(2编辑  收藏  举报