Solved Connecting to WiFi network using iw command

Solved issue

CaffeineAddict

Well-Known Member
Joined
Jan 21, 2024
Messages
1,834
Reaction score
1,382
Credits
15,148
There are several methods online about how to connect to Wi-Fi network however all those tutorials and guides are kind of deprecated and I found none that would do it by iw command alone.

Here are steps I come out with, but there is problem...

Scan for available Wi-Fi networks:

Bash:
# List available Wi-Fi NIC's
sudo iw dev
# Scan for Wi-Fi networks with selected NIC
sudo iw dev wlan0 scan

Output:

Bash:
#<snip>
SSID: Wi-Fi-Name
#<snip>
RSN: * Version: 1
     * Group cipher: CCMP
     * Pairwise ciphers: CCMP
     * Authentication suites: PSK
#<snip>

Connect to one of the Wi-Fi networks listed:

Bash:
# Generate PSK key
wpa_passphrase Wi-Fi-Name

# Connect to Wi-Fi
sudo iw dev wlan0 connect -w Wi-Fi-Name auth<open|shared> key psk:<PSK Key> <AKM Suite> <pairwise CIPHER> <groupwise CIPHER>
# <PSK Key> = PSK key made with wpa_passphrase
# <AKM Suite> = Output of Authentication suites
# <pairwise CIPHER> = Pairwise ciphers
# <groupwise CIPHER> = Group cipher

And finally moment of truth:

Bash:
sudo iw dev wlan0 connect -w Wi-Fi-Name auth shared key psk:6f150a5617d69c6eaf7b7b042c2f4bcb322884aae9c39698 PSK CCMP CCMP

This command results in the following error:

Code:
command failed: Invalid argument (-22)

Why and how to fix it?
I'm connecting to WPA2 PSK network.
 


I would use nmcli instead of iw, if it was me.

nmcli dev wifi list

nmcli dev wifi conn OutlawCave password "mysecretpassword"

or in your case....

nmcli dev wifi conn OutlawCave wifi-sec.key-mgmt wpa-psk wifi-sec.psk "your_shared_psk"
Obviously change OutlawCave to whatever your WiFi SSID is.
 
I see you are working your way up to moving to Arch Linux ;)
It's tempting and was already considering getting rid of Debian on many occasions.
If I ever dump Debian my only alternatives will be either Arch or Kali.

But not anytime soon, I like stability, secure system and huge Debian's repo, Debian is also great to learning Linux because don't have to troubleshoot bugs, incompatibilities, regressions and other stuff that come with rolling-release distros like Arch or Kali.
 
There are several methods online about how to connect to Wi-Fi network however all those tutorials and guides are kind of deprecated and I found none that would do it by iw command alone.
From kernel docs on iw:
Not connected.

This would happen if you are not connected to an AP. To connect to an AP
you can use iw connect if the connection requires:

• No encryption
• Uses WEP for encryption If you need to connect to an AP with WPA or
WPA2 encryption requirements then you must use [66]wpa_supplicant.
see: https://wireless.wiki.kernel.org/en/users/documentation/iw

Debian docs may also be useful:

Without being particularly wifi adept, this is how I configure and connect:
Code:
ip a
wpa_passphrase wifiName wifiPasswd  >  /etc/wpa_supplicant/wpa_supplicant.conf
wpa_supplicant -B -c /etc/wpa_supplicant/wpa_supplicant.conf -i interfaceName
dhclient interfaceName

Then set up /etc/network/interfaces for persistence.
 
Last edited:


Top