Connect to wifi from command line on linux systems through the iwd (wireless daemon for linux)

The iwd is the up-and-coming wireless daemon for linux released by
Intel and the wpasupplicant successor. The development of iwd is still in progress, but it is packaged under some linux distribution Gentoo, Arch-linux , Ubuntu (Cosmic) and Debian (Buster and Sid)…

The configuration of the network and the connection is possible through the interactive mode using iwctl , the help command will display the list of the available commands (no manpage ).

Without using the interactive mode :

  1. How can I manually configure the wifi credentials?
  2. How can I connect to the configured wifi through iwctl?
  3. How can I automatically enable the wifi connection at boot?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

1) From the non-interactive mode , you can scan and list the available access points :

iwctl station wlp8s0 scan
iwctl station wlp8s0 get-networks

The wifi credentials are stored under /var/lib/iwd , the exact name of the SSID should be used , the format:

SSID.psk

The content:

[Security]
PreSharedKey=encripted-password
Passphrase=the-plain-txt-password

The minimal configuration file should contain the encrypted wifi paswword (PreSharedKey)

To generate an encrypted psk , you can use the wpa_passhrase tool:

wpa_passhrase "My-SSID" passphrase

There is an example using “My SSID” and mysecretpassword:

$ cat My SSID.psk
[Security]
PreSharedKey=8e1e64a6ecaf2b5e0aa29816547af300d7f3b0473bbfa56ddb5514ad4683804c

2) To connect from the terminal:

iwctl station <INTERFACE> connect "SSID"

e,g:

iwctl station wlp8s0 connect "My SSID"
dhclient

dhclient can be replaced an iproute2 command to assign an IP address to wlp8s0.

3) to automatically enable the wifi connection at boot , there is a way using a systemd service:

A minimal script to connect:

$ cat /usr/local/enable-wifi.sh

#!/bin/bash
iwctl station wlan0 connect "My SSID" 
dhclient

Create a systemd service.

$ cat /etc/systemd/system/enable-wifi.service

[Unit]
Before=network.target
Wants=network.target

[Service]
ExecStart=/usr/local/enable-wifi.sh

[Install]
WantedBy=default.target

then :

# chmod 744 /usr/local/enable-wifi.sh
# chmod 664 /etc/systemd/system/enable-wifi.service
# systemctl daemon-reload
# systemctl enable enable-wifi.service

documentation:

arch-linux wiki : iwd

Debian wiki: NetworkManager/iwd

lwn: iwd: simplifying WiFi management


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x