树莓派命令行配置无线网络和SSH远程登陆

无线网络配置
  1. 查找可用的网络
pi@raspberrypi:~ $ sudo iwlist wlan0 scan

wlan0     Scan completed :
          Cell 01 - Address: 9C:B2:B2:C9:AB:B6
                    Channel:1
                    Frequency:2.412 GHz (Channel 1)
                    Quality=44/70  Signal level=-66 dBm  
                    Encryption key:off
                    ESSID:"CHEN-OPEN"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s
                              24 Mb/s; 36 Mb/s; 54 Mb/s
                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s
                    Mode:Master
                    Extra:tsf=0000000000000000
                    Extra: Last beacon: 162520ms ago
                    IE: Unknown: 00044348454E
                    IE: Unknown: 010882848B962430486C
                    IE: Unknown: 030101
                    IE: Unknown: 2A0100
                    IE: Unknown: 32040C121860
                    IE: Unknown: 2D1A210017FF00000000000000000080010000000000000000000000
                    IE: Unknown: 3D1601080400000000000000000000000000000000000000
                    IE: Unknown: 7F080400008001000040
                    IE: Unknown: DD1E00904C0408BF0C3250800FFEFF0000FEFF0000C0050001000000C3020002
                    IE: Unknown: DD090010180201101C0000
                    IE: Unknown: DD180050F2020101800003A4000027A4000042435E0062322F00
          Cell 02 - Address: 9C:3A:9A:82:CA:61
                    Channel:3
                    Frequency:2.422 GHz (Channel 3)
                    Quality=39/70  Signal level=-71 dBm  
                    Encryption key:on
                    ESSID:"test-link"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                              9 Mb/s; 12 Mb/s; 18 Mb/s
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=0000000000000000
                    Extra: Last beacon: 100ms ago
                    IE: Unknown: 00027366
                    IE: Unknown: 010882848B960C121824
                    IE: Unknown: 030103
                    IE: Unknown: 050400010100
                    IE: Unknown: 0706434E20010D1E
                    IE: Unknown: 2A0100
                    IE: Unknown: 32043048606C
                    IE: Unknown: 2D1AAD011BFFFF0000000000000000000001000000000406E6A70C00
                    IE: Unknown: 3D1603080400000000000000000000000000000000000000
                    IE: Unknown: 4A0E14000A002C01C800140005001900
                    IE: Unknown: 7F080100000000000040
                    IE: Unknown: DD180050F2020101000003A4000027A4000042435E0062322F00
                    IE: Unknown: DD0A02115A01020100000002
                    IE: Unknown: DD0E02115A0101019C3A9A02CA610000
                    IE: Unknown: DD0A02115A01030100000000
                    IE: Unknown: DD0A02115A01040100000000
                    IE: Unknown: DD0900037F01010000FF7F
                    IE: WPA Version 1
                        Group Cipher : TKIP
                        Pairwise Ciphers (2) : CCMP TKIP
                        Authentication Suites (1) : PSK
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : TKIP
                        Pairwise Ciphers (2) : CCMP TKIP
                        Authentication Suites (1) : PSK
  1. 修改配置文件
pi@raspberrypi:~ $ sudo vi /etc/wpa_supplicant/wpa_supplicant.conf

文件内容为

country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

如果连接连接开放网络,在文件末尾添加

network={
ssid=“CHEN-OPEN”
key_mgmt=NONE
}

如果连接连接加密网络,在文件末尾添加

network={
ssid=“test-link”
key_mgmt=WPA-PSK
psk=“12345678”
}

  1. 查看连接是否成功
    修改上述文件后,一般情况下会自动进行连接.
    如果显示IP地址则表示连接成功
pi@raspberrypi:~ $ ifconfig wlan0
wlan0     Link encap:Ethernet  HWaddr b8:27:eb:c6:a9:85  
          inet addr:192.168.43.59  Bcast:192.168.43.255  Mask:255.255.255.0
          inet6 addr: 2409:8920:610:d61:314e:7d16:36dd:1d36/64 Scope:Global
          inet6 addr: fe80::ff30:bce8:b49d:b9a8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:534 errors:0 dropped:0 overruns:0 frame:0
          TX packets:468 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:43155 (42.1 KiB)  TX bytes:113503 (110.8 KiB)
  1. 手动连接
    如果不显示IP,则表示自动连接不成功。此时可以手动进行连接,查看输出的错误详情
    (下面这个是成功情况下的回显)
pi@raspberrypi:~ $ sudo wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf  -i wlan0

Successfully initialized wpa_supplicant
ctrl_iface exists and seems to be in use - cannot override it
Delete '/var/run/wpa_supplicant/wlan0' manually if it is not used anymore
Failed to initialize control interface 'DIR=/var/run/wpa_supplicant GROUP=netdev'.
You may have another wpa_supplicant process already running or the file was
left by an unclean termination of wpa_supplicant in which case you will need
to manually remove this file before starting wpa_supplicant again.
SSH远程登陆配置

树莓派命令行配置无线网络和SSH远程登陆_第1张图片
在sd卡的boot分区中添加空文件ssh即可

你可能感兴趣的:(树莓派,树莓派)