2

I've seen how one can connect to a hidden wifi network using the following:

nmcli c add type wifi con-name $ssid ifname $adapter ssid $ssid
nmcli con modify $ssid wifi-sec.key-mgmt wpa-psk
nmcli con modify $ssid wifi-sec.psk $password
nmcli con up $ssid

In the code above the connection name is being set the same name as the SSID just for clarity.

However, this requires me to know the type of wifi authentication.

When connecting to a AP broadcasting it's SSID it appears that Network Manager can figure out what type of authentication is being used thus I only need to provide the password using something like this:

nmcli -w 30 device wifi connect $ssid password $password ifname $adapter

Is there a way to connect to a hidden wifi AP using nmcl such that I only need to provide the password, SSID and device and not the type of authentication used similar to how connecting to a non-hidden AP doesn't require me to specify authentication type?

1

When using nmcli with device wifi connect, try setting the hidden option to yes.

Excerpt from the manual[1]:

wifi connect (B)SSID [password password] [wep-key-type {key | phrase}] [ifname ifname] [bssid BSSID] [name name] [private {yes | no}] [hidden {yes | no}]
  Connect to a Wi-Fi network specified by SSID or BSSID. The command finds a matching connection or creates one and then activates it on a device. This is a
  command-line counterpart of clicking an SSID in a GUI client. If a connection for the network already exists, it is possible to bring up (activate) the existing
  profile as follows: nmcli con up id name. Note that only open, WEP and WPA-PSK networks are supported if no previous connection exists. It is also assumed that
  IP configuration is obtained via DHCP.

  If --wait option is not specified, the default timeout will be 90 seconds.

  Available options are:

  [...]

  hidden
    set to yes when connecting for the first time to an AP not broadcasting its SSID. Otherwise, the SSID would not be found and the connection attempt would
    fail.


  [1]: https://developer.gnome.org/NetworkManager/stable/nmcli.html
2
  • Thank you. I will give this a try. If it works I will accept this answer.
    – Chimera
    Mar 4 at 18:12
  • Doesn't work on version 1.22.10 nmcli -w 30 device wifi connect somessid password hiddenpw hidden yes ifname wlan0 Output: Error: No network with SSID 'somessid' found. But if I add hidden no to a network broadcasting it's SSID then it works.
    – Chimera
    Mar 4 at 18:31
1

Usually nmcli device wifi connect "$SSID" is the solution here. This would create a new profile, if no profile exists yet.

However, that requires that NetworkManager found the network in the scan result, otherwise it doesn't know which settings to set. Since the network is hidden, it might not be there. To solve that, first explicitly scan for the SSID with nmcli device wifi rescan ssid "$SSID" so that you find it in the scan result (nmcli device wifi).

The right solution should be indeed what user234931 says (nmcli device wifi connect "$SSID" hidden yes), but I am not sure that actually works. Maybe it does, otherwise it should be fixed in NetworkManager :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.