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

无显示器如何通过配置文件快速修复树莓派无法通过 SSH 访问的问题 All In One

无显示器如何通过配置文件快速修复树莓派无法通过 SSH 访问的问题 All In One

在没有显示器的情况下如何通过配置系统文件快速的修复树莓派无法通过 SSH 访问的问题 All In One

无显示器 SSH 远程访问 树莓派

# SSH
$ ssh pi@raspberrypi.local

不小心或不知道怎么把 SSH 关闭了, 导致无法 SSH 访问了 ❌

$ ping raspberrypi.local
ping: cannot resolve raspberrypi.local: Unknown host
# SSH 使用主机名 (mDNS 🚀)
$ ssh pi@raspberrypi.local
# 卡住了, 一直没有响应 ❌

# SSH 使用 IP 地址
$ ssh pi@192.168.18.135
ssh: connect to host 192.168.18.135 port 22: Operation timed out

image

Raspberry Pi Headless 模式 ✅

  • 开启 SSH
  • 配置 用户
  • 配置 Wi-Fi

Steps 操作步骤

  1. SD 卡根目录下(boot partition / 启动分区),创建一个 ssh 无扩展名的空文件

  2. SD 卡根目录下(boot partition / 启动分区),创建一个 userconf.txt 文件,配置用户名:密码

pi:/4g6TptuTP5B6

pi:raspberry 密码需要加密才行

# macOS
$ openssl passwd
# 跳过二次验证
$ openssl passwd -noverify

  1. SD 卡根目录下(boot partition / 启动分区),创建一个 wpa_supplicant.conf 文件,配置 Wi-Fi 如下
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=CN

network={
  scan_ssid=1
  ssid="xgqfrms's wifi"
  psk="password_of_wifi"
  proto=RSN
  key_mgmt=WPA-PSK
  pairwise=CCMP
  auth_alg=OPEN
}


IP

# Windows
$ ipconfig

# Linux
$ ifconfig

$ iwconfig

$ hostname -I

# ip
$ ip

image

# macOS ❌
$ hostname -I

image

$ sudo apt-get install nmap

$ nmap -sn 192.168.1.0/24

image

https://www.raspberrypi.com/documentation/computers/remote-access.html#how-to-find-your-ip-address

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

wifi scan

iwlist

# scanning for wireless networks
$ sudo iwlist wlan0 scan

$ sudo iwlist wlan0 scan > wifi-scan.md

$ cat ./wifi-scan.md | grep ESSID

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

others

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

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

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

https://www.raspberrypi.com/documentation/computers/configuration.html#wpa_supplicant-conf

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

https://www.raspberrypi.com/documentation/computers/remote-access.html#ssh

config.txt / cmdline.txt / issue.txt

  1. config.txt

/Volumes/bootfs/config.txt

  1. cmdline.txt

/Volumes/bootfs/cmdline.txt

  1. issue.txt

/Volumes/bootfs/issue.txt

$ cp /Volumes/bootfs/config.txt /Users/xgqfrms-mm/Documents/github/dd-robot-notice/raspberry-pi/

$ cp /Volumes/bootfs/cmdline.txt /Users/xgqfrms-mm/Documents/github/dd-robot-notice/raspberry-pi/

$ cp /Volumes/bootfs/issue.txt /Users/xgqfrms-mm/Documents/github/dd-robot-notice/raspberry-pi/

mDNS

$ cat /etc/hostname

image

https://www.raspberrypi.com/documentation/computers/remote-access.html#resolving-raspberrypi-local-with-mdns

$ nmap -sn 192.168.1.0/24

https://www.raspberrypi.com/documentation/computers/remote-access.html#nmap-command

$ hostname -I
192.168.18.135 fd80:eae6:1258:0:d1c5:2a7f:abad:cbb5
pi@raspberrypi:~ $ ifconfig | grep inet 
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        inet 192.168.18.135  netmask 255.255.255.0  broadcast 192.168.18.255
        inet6 fe80::a1d2:9993:d9dc:b546  prefixlen 64  scopeid 0x20<link>
        inet6 fd80:eae6:1258:0:d1c5:2a7f:abad:cbb5  prefixlen 64  scopeid 0x0<global>
pi@raspberrypi:~ $ ifconfig | grep "inet "
        inet 127.0.0.1  netmask 255.0.0.0
        inet 192.168.18.135  netmask 255.255.255.0  broadcast 192.168.18.255
pi@raspberrypi:~ $ hostname -I
192.168.18.135 fd80:eae6:1258:0:d1c5:2a7f:abad:cbb5 

image

https://www.raspberrypi.com/documentation/computers/remote-access.html#getting-ipv6-addresses-by-pinging-from-a-second-device

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

refs

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

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

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

Raspberry PI 设置开机自启动脚本 All In One

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



©xgqfrms 2012-2021

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

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


posted @ 2023-04-16 14:56  xgqfrms  阅读(198)  评论(3编辑  收藏  举报