最近新入手了一块raspberry Pi zero板子,使用串口连接树莓派的话,不太方便,就想用先连接wifi,然后用ssh登陆比较好。
树莓派使用的系统是:2017-04-10-raspbian-jessie-lite.img
无线网卡
raspberry Pi zero没有自带wifi模块,需要另外购买一个usb无线网卡。我使用的是EDUP网卡,如下图所示:
1,插入usb 无线网卡,使用命令lsusb,查看usb无线网卡是否正常加载。
pi@raspberrypi:~ $ lsusb
Bus 001 Device 006: ID 046d:c077 Logitech, Inc.
Bus 001 Device 004: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter
Bus 001 Device 003: ID 046d:c31c Logitech, Inc. Keyboard K120 for Business
Bus 001 Device 002: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
pi@raspberrypi:~ $
RTL8188CUS 802.11n ---这行则是无线网卡的驱动信息。
2,扫描附近wifi,进一步确认usb 无线网在正常工作。
命令: sudo iwlist wlan0 can
3,配置wifi连接信息
修改/etc/network/interfaces文件
命令: sudo nano /etc/network/interfaces
修改的地方如图所示
pi@raspberrypi:~ $ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet manual
#allow-hotplug wlan0
#iface wlan0 inet manual
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
#allow-hotplug wlan1
#iface wlan1 inet manual
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-ssid "xxxxxx"
wpa-key "xxxxxx"
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
wpa-ssid 设置要连接的wifi的ssid
wps-key 设置要连接的wifi的密码
4,修改 /etc/wpa_supplicant/wpa_supplicant.conf 文件
pi@raspberrypi:~ $ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf
country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="xxxxxxxx" -----设置wifi 的ssid
psk="xxxxxxxx" ------设置 wifi的密码
}
5,允许SSH 远程连接
a,安装没有桌面界面的系统(2017-04-10-raspbian-jessie-lite.img),则直接运行命令:sudo rasp-config ,打开配置界面,点击高级选项,出现SSH的选项,enable即可。
b,安装有桌面的系统(2017-04-10-raspbian-jessie.img),则点击左上角树莓派图标--->点击Preferens--->Raspberry Pi Configuration --->interfaces -->SSH enabled 即可
6,重启网路服务
sudo /etc/init.d/networking restart
7,执行ifconfig命令,则可以看到ip地址,
然后可以远程ssh登陆。