Every time I log in to my user account "bob" I have to use these commands (with sudo or in the root account) to connect to the WiFi:

wpa_supplicant -B -D wext -i wlan0 -c /etc/wpa_supplicant.conf
dhclient wlan0

wpa_supplicant -B -D wext -i wlan0 -c /etc/wpa_supplicant.conf gives me this result :

Successfully initialized wpa_supplicant
Could not set interface wlan0 flags (UP): Operation not permitted
WEXT: Could not set interface 'wlan0' UP
wlan0: Failed to initialized driver interface

And for dhclient wlan0 I get:

RTNETLINK answers: Operation is unreachable

I am doing this on a Raspberry PI 4 with Debian 10 Codename: buster.

I have systemd.

How do I set up my environment so that every time I boot up, or I log in with "bob" or even root, my system connects to the WiFi?

I was thinking of using the commands I just showed and put them in .profile but I cannot run them with the "bob" account.


Your wifi credentials go to /etc/wpa_supplicant/wpa_supplicant.conf.

The file should look like

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

    ssid="<wifi name>"
    psk="<wifi password>"

The Pi will now autoconnect on every boot (or when in reach of the wifi). To reload the wifi after applying the changes, use sudo systemctl restart dhcpdc. You may add more network= blocks if you have several wifis you regularly connect to.

You may also remove the SD card and place a file wpa_supplicant.conf with the above content in the /boot-section of the SD to load it on a fresh install of Raspberry Pi OS.


A cron job to run the desired commands for you.

Create a script autocnnect.sh:

cat <<EOF > autoconnect.sh
/usr/sbin/wpa_supplicant -B -D wext -i wlan0 -c /etc/wpa_supplicant.conf
sleep 0.5
/usr/sbin/dhclient wlan0 >/dev/null 2>&1

make it executable

chmod +x autoconnect.sh

As root, run crontab -e then add the following line:

@reboot /path/to/autoconnect.sh

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.