How to connect to hidden wifi network using nmcli [closed]
Asked Answered
B

4

17

I have to write a linux desktop software which connects to a hidden wifi network. If the network is not hidden, my code can connect by calling nmcli, but if it is hidden, it can not add the connection. However, I can create a new network using the GUI of the Network Manager, so I think it is not impossible. Do you have any ideas?

Bierce answered 18/2, 2016 at 8:36 Comment(0)
B
30

Okay, I have the solution. We know the ssid and the password.

nmcli c add type wifi con-name <connect name> ifname wlan0 ssid <ssid>
nmcli con modify <connect name> wifi-sec.key-mgmt wpa-psk
nmcli con modify <connect name> wifi-sec.psk <password>
nmcli con up <connect name>

If we dont need the connection anymore:

nmcli c delete <connect name>
Bierce answered 18/2, 2016 at 14:42 Comment(2)
Just to be clear. When doing delete, <connect name> is either id NAME or uuid UUID where NAME and UUID can be obtained via nmcli -p c. E.g. nmcli c delete id esp8266_ap. This is referring to nmcli tool, version 0.9.8.8.Sevenup
best thing of doing this is that once added, it is persistent. Reboot/shutdown, it shall keep your connection up once linux is initiated!Aldridge
S
16

This works fine for me:

nmcli dev wifi connect "abc" password 123 hidden yes
Suppletory answered 21/5, 2017 at 22:6 Comment(2)
This didn't work for me™ I received an error: "network manager failed to scan hidden SSID: Scanning not allowed while already scanning." The selected answer worked for me however.Score
You just need to wait a few seconds for the scan to finish.Lid
B
2

While doing some experimenting, I found that you can use both echnotux's and Pocokman's answers to get it to connect. i.e

nmcli c add type wifi con-name <connect name> ifname wlan0 ssid <ssid>
nmcli dev wifi connect <ssid> password <password> hidden yes
nmcli c delete <connect name>

This simplifies it quite a bit.

Bournemouth answered 10/11, 2017 at 17:51 Comment(0)
B
0

As of 2023, it is much easier to setup a connection with a hidden SSID using nmcli:

nmcli dev wifi connect --ask <ssid> name <ssid> hidden yes

You can also use password <password> if you don't want to use --ask.

Blunge answered 28/9, 2023 at 2:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.