自言自语

I'm Wang Xianyuan, writing for myself, more studying, more experience…

SSH配置Wi-Fi连接的方法

By

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

#! /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 中加入这两行配置就行了:

# 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

One Comment

  1. April 10, 2016 at 2:30 pm

    […] via […]