Configure wpa_supplicant via SSH via commands / config files

I am trying to configure the WIFI settings via SSH with commands, but it looks like there is an alternative method/command as most of the file system is read-only.

These commands:

mkdir -p /etc/wpa_supplicant/
wpa_passphrase {{wifi_ssid}} {{wifi_psw}} > /etc/wpa_supplicant/wpa_supplicant.conf


mkdir: can't create directory '/etc/wpa_supplicant/': Read-only file system
can't create /etc/wpa_supplicant/wpa_supplicant.conf: nonexistent directory

However I am able to enable/restart the SyestemD daemon with:

systemctl enable wpa_supplicant
systemctl restart wpa_supplicant
systemctl status wpa_supplicant

Also: from the Kodi GUI I can see a list of WIFI networks (although I can not find commonly available commands like wpa_cli or iwlist), so there must be a way to configure a WIFI connection with some sort of command.

Is there a way to automate the WIFI configuration with bash commands? How can I automate this?

You are using wrong folders.
Have a look at /storage/.cache/connman

I can see there is a conf file: /storage/.cache/connman/settings


I also see a directory with the Ethernet details.

Is there a command to write into that directory?

1 Like

There is a command - connmanctl
But I never used this.
Sorry, that´s all I know about this.

OK, so I’ve been tinkering for a while and I think the following setup should work because I can not see anything wrong in the SystemD logs, however it doesn’t make the Tv Box connect to the Wifi network (no IP address shows up when using ifconfig)

Enable the Wifi thing with connmanctl enable wifi.

Find your wifi network unique ID with connmanctl scan wifi && connmanctl services. It should be something like: wifi_<some_unique_id>_<some_other_unique_id>_managed_psk

Create this settings file at: /storage/.cache/connman/wifi_<some_unique_id>_<some_other_unique_id>_managed_psk/settings
with the content:

Name={{ my_wifi_ssid }}
Passphrase={{ my_wifi_password }}

where {{ my_wifi_ssid }} is the usual name of the Wifi network you would see from anywhere e.g. from your phone.

Restart the SystemD service for Connman with: systemctl restart connman.

I checked the status with systemctl status connman and the logs with journalctl -u connman but I don’t see anything suspicious like error messages or warnings.
The only strange thing I see is a message saying wlan0 {newlink} index 3 operstate 5 <DORMANT>, but that’s the network interface and it’s been up and enabled because I can see it from the output of ifconfig. Also I can see it’s enabled from the output of: /storage/.cache/connman/settings.

What should I do to connect to a Wifi network using commands and configuration files?
What’s wrong with the above procedure?