树莓派通过SSH配置Wi-Fi连接

脚本如下,修改其中的SSID、ENCRYPTION以及PASSWORD。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#! /bin/sh
# SSID (aka. network name).
SSID='Tenda'
# Network encryption method.
# * 'WPA' for WPA-PSK/WPA2-PSK (note: most Wi-Fi networks use WPA);
# * 'WEP' for WEP;
# * 'Open' for open network (aka. no password).
ENCRYPTION='WPA'
# Network password. (WPA-PSK/WPA2-PSK password, or WEP key)
PASSWORD='pass'
if [ $(id -u) -ne 0 ]; then
printf "This script must be run as root. \n"
exit 1
fi
NETID=$(wpa_cli add_network | tail -n 1)
wpa_cli set_network $NETID ssid \"$SSID\"
case $ENCRYPTION in
'WPA')
wpa_cli set_network $NETID key_mgmt WPA-PSK
wpa_cli set_network $NETID psk \"$PASSWORD\"
;;
'WEP')
wpa_cli set_network $NETID wep_key0 $PASSWORD
wpa_cli set_network $NETID wep_key1 $PASSWORD
wpa_cli set_network $NETID wep_key2 $PASSWORD
wpa_cli set_network $NETID wep_key3 $PASSWORD
;;
*)
;;
esac
wpa_cli enable_network $NETID
wpa_cli save_config

等待几秒钟之后,无线网卡上的指示灯亮起,树莓派即连接成功。
可能用到的命令:
lsusb – 查看USB设备,检查无线网卡。
lsmod – 查看系统已加载的模块。rt2x00 是 Ralink 芯片组的统一驱动。
iwconfig – 查看网卡信息。
ifconfig – 查看连接信息。ifconfig wlan0 up 启动网卡 wlan0。
供电不足可能会导致USB无线网卡易掉线等问题,需要保持电力供应。
如果在wpa_gui中找不到网卡适配器,在 /etc/wpa_supplicant/wpa_supplicant.conf 中加入这两行配置就行了:

1
2
3
4
# needed for wpa_gui to work
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
# needed to allow wpa_gui to alter the configuration
update_config=1

via

本站原创文章,作者:小 编,如若转载,请注明出处:https://www.mzbky.com/1736.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
小 编的头像小 编新注册
上一篇 2020年3月1日 下午2:56
下一篇 2020年3月1日 下午7:57

相关推荐

发表回复

登录后才能评论