How to connect to wifi on startup

Hello,

i’m running a fedora-32-server and trying to get this thing to connect to a wifi on startup (even before i log in). I added a connection via nmcli which i can manually connect to.

nmcli device set IFNAME autoconnect yes nor
nmcli connection modify CONNAME autoconnect yes

have the desired effect. Does anybody know how to do the trick?

Thanks in advance, greets jake

Hi,

Could try with systemd:

[Unit]
Description=Auto connect wifi
After=multi-user.target

[Service]
ExecStart=/usr/bin/nmcli device wifi connect *Wifi SSID* password *wifi password*

[Install]
WantedBy=multi-user.target

Thanks Tom.

1 Like

What is the result of this command?
nmcli connection show
Do you have more than one connection?
Once started, how do you manage to connect? It automatically connects only when you log in?

1 Like

My laptop uses WiFi, and I have a connection configured for it through NetworkManager. I’ve told it that the connection is available to all users and to connect automatically if available, and as far as I can tell, it’s connected before I log in. Is there any reason that you can’t use NetworkManager for this?

@sideburns, @Jackson actually uses NetworkManager, but from the command line. Probably the connection configuration lacks of some bit (like the option you have mentioned).

If you use the GUI, those options are on the General Tab.

Thx, but things should work “headless”, so i would like to prevent installing an desktop environment.

$ nmcli connection show
NAME	UUID									TYPE		DEVICE
enp3s0	3b218921-ba3f-3d81-a6b8-c707aa2497d8	ethernet	--
Jake	e09ea4ca-c0b6-4a85-b197-c9612974bc27	wifi		--

I followed this guide to create the systemd service file.

$ sudo touch /etc/systemd/system/jake-wifi.service
$ sudo chmod 664 /etc/systemd/system/jake-wifi.service
$ sudo nano /etc/systemd/system/jake-wifi.service
$ sudo systemctl daemon-reload
$ sudo systemctl enable jake-wifi.service
$ sudo reboot now

doing so with following jake-wifi.service

$ cat /etc/systemd/system/jake-wifi.service
[Unit]
Description=auto connect wifi on startup
After=multi-user.target

[Service]
ExecStart=/usr/bin/nmcli device wifi connect Jake password IamAPassword

[Install]
WantedBy=multi-user.target

throws an error alike “SSID Jake not found” (checked after boot with $ systemctl status jake-wifi.service).

I should have mentioned that my wifi is hidden, so i changed the “ExecStart” line in the systemd service file to

ExecStart=/usr/bin/nmcli connection up Jake

rebooted - et voila - wifi is up without me doing anything, thank you very much!

Ps.: I created the connection for the hidden wifi beforehand, like stated here.

2 Likes

Frankly speaking, the systemd unit is redundant here.
What you need is to make sure the connection is actually configured with hidden SSID:

nmcli -g 802-11-wireless.hidden connection show id Jake
nmcli connection modify id Jake 802-11-wireless.hidden yes

OK, fair enough, if this is considered a solution. However, note that the general requirement to autoactivate a Wi-Fi profile is what NetworkManager is supposed to do.

A common obstacle is that you set connection.permissions. This prevents autoconnect, until the user is logged in. Another common issue is that you need to actually store the secrets in the profile itself (in plain-text, accessible to root only). You do that by setting the secret flags to zero, like wifi.psk-flags=0.

2 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.