lk/networking/wpa_supplicant.md

103 lines
1.8 KiB
Markdown
Raw Permalink Normal View History

2022-01-16 18:20:39 +00:00
---
title: "wpa_supplicant"
2022-01-26 22:35:07 +00:00
tags: [ "Documentation", "Networking" ]
2022-01-16 18:20:39 +00:00
---
2020-01-02 00:04:35 +00:00
wpa_supplicant configurations are stored in /etc/wpa_supplicant/wpa_supplicant-wlan0 (or equivalent).
2022-11-06 13:28:09 +00:00
## WiFi Connection
2020-01-02 00:04:35 +00:00
```bash
wpa_cli
```
2020-01-02 00:04:35 +00:00
2022-11-06 13:28:09 +00:00
Once in, scan the network, add an empty place to store credentials, then input them.
2020-01-02 00:04:35 +00:00
```bash
scan
```
2020-01-02 00:04:35 +00:00
```bash
scan_results
```
2020-01-02 00:04:35 +00:00
```bash
add_network
```
2020-01-02 00:04:35 +00:00
2022-06-18 13:18:17 +00:00
This outputs a network number, e.g. '3'. This is the new network you'll work with.
2020-01-02 00:04:35 +00:00
```bash
set_network *3* ssid *"Kosachok Cafe"*
```
2020-01-02 00:04:35 +00:00
```bash
set_network 3 psk *"Kosachok2019"*
```
2020-01-02 00:04:35 +00:00
2022-06-18 13:18:17 +00:00
OR (for no password)
2020-01-02 00:04:35 +00:00
```bash
set_network *3* key_mgmt NONE
```
2020-01-02 00:04:35 +00:00
```bash
enable_network 3
```
2020-01-02 00:04:35 +00:00
```bash
save_config
```
2020-01-02 00:04:35 +00:00
2022-11-06 13:28:09 +00:00
This takes a while to connect, so to speed things up, restart the service:
2020-01-02 00:04:35 +00:00
```bash
sudo sv restart wpa_supplicant
```
2020-01-02 00:04:35 +00:00
2022-11-06 13:28:09 +00:00
# Scripts
2020-01-02 00:04:35 +00:00
2022-06-18 13:18:17 +00:00
You can script like this:
```bash
wpa_cli add_network
```
2022-06-18 13:18:17 +00:00
That returns an ID, so you can say:
```bash
newNetwork="$(wpa_cli add_network)"
```
2022-06-18 13:18:17 +00:00
Then `$newNetwork` would equal that number, and you can add/ remove networks with scripts.
But remember to escape the quotes, so adding a network would be:
```bash
wpa_cli set_network *3* psk *\""passphrase"\"*
```
2020-01-02 00:04:35 +00:00
2022-11-06 13:28:09 +00:00
## Generating Keys Manually
```bash
wpa_passphrase [ssid] [password]
```
2022-11-06 13:28:09 +00:00
For example:
```bash
wpa_passphrase 'Cafe Kosachok' 'Kosachok2019'
```
2022-11-06 13:28:09 +00:00
This then spills the relevant psk and such to be entered into the wpa_supplicant configuration file.
If you encounter problems, you will probably need to delete the old device pid in (e.g.) /run/wlan0/
Next up, start wpa_supplicant:
```bash
wpa_supplicant -B -iwlan0 -c /etc/wpa_supplicant/wpa_supplicant-wlan0
```
2022-11-06 13:28:09 +00:00
The -B flag runs this as a background process. Remove this to see real-time output in order to solve problems. The -i flag denotes the physical device used for the wifi. The -c flag points to the configuration file for use.