Move Pi to new WLAN - HowTo

Hi

I am running the latest updated light version on my Pi Zero 2WH.

Whilst initial setup i configured successfully the wifi connection.

Now i have moved this pi to a new physical location. Of course the wifi credentials are different from the initial ones.

Which file in the SDHC do i need to edit in order to get a connection to the new wifi network at the new location? Thx.

Hello,

you probably edited dietpi.txtto config some stuff (like the wifi) on the very first boot after flashing. But these settings only apply on the first boot, so you can not use this file anymore to change the wifi settings.

Now you need to directly edit the wifi config, which is located at:

/etc/wpa_supplicant/wpa_supplicant.conf 

Hi. Thx. for your reply. This is the files content here:

# WiFi country code, set here in case the access point does send one

country=DE

# Grant all members of group “netdev” permissions to configure WiFi, e.g. via wpa_cli or wpa_gui

ctrl_interface=DIR=/run/wpa_supplicant GROUP=netdev

# Allow wpa_cli/wpa_gui to overwrite this config file

update_config=1

That’s it. I can’t see anything related to the new environment like SSID, Passphase etc. …..

Hello

it’s look like this with SSID and passphrase

# WiFi country code, set here in case the access point does send one
country=FR
# Grant all members of group "netdev" permissions to configure WiFi, e.g. via wpa_cli or wpa_gui
ctrl_interface=DIR=/run/wpa_supplicant GROUP=netdev
# Allow wpa_cli/wpa_gui to overwrite this config file
update_config=1
network={
        ssid="SFR_xxxx"
        scan_ssid=1
        key_mgmt=WPA-PSK
        psk=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
}
network={
        ssid="Livebox-xxxx"
        scan_ssid=1
        key_mgmt=WPA-PSK
        psk="xxxxxxxxxxxxxxxxxxxxxxxxx"
}

Thx. a lot!

Question… I recently went to do the same thing on a RPi Zero W and Zero 2W due to a change to the name of my WAP, but when I mounted the microSD card on my Chromebook, /etc/wpa_supplicant/wpa_supplicant.conf had permissions 0600, with owner/group ‘nobody/nobody’. As a result, even as the root user (on the Chromebook) I couldn’t edit the file. I didn’t want to get too rambunctious with it, so I ended up just changing the WAP name back temporarily, and ssh’ing back into the RPi’s and editing the file directly on the device to add a new network with the modified name.

Is there some trick I missed when mounting the micro SD card, that I wasn’t able to edit the files, even as root?

Usually root should have permissions always. And you would need to go to the mounted directory. If you go straight to /etc/wpa_supplicant/wpa_supplicant.conf, it’s the file from host system and not from mounted device.

ChromeOS has a kinda weird way of mounting stuff so it’s available to the Linux subsystem… you have to select the desired file/folder, click through some options to ‘make it available to Linux’, and then it gets mounted under /mnt/chromeos/removable. So if I plug in the micro SD card, it auto mounts, and opens in the Files app. Navigate to the second partition, find the /etc/wpa_supplicant directory, make it available to Linux, then open the terminal and navigate to it via the CLI. From there I can do most of the usual Linux stuff - ls, less, cat, vim, etc.

Problem is, I’m guessing, the uid/gid on the dietpi file system doesn’t map to anything in the ChromeOS system, so it gets mounted as owned by nobody/no group, permission 0600 ie -rw------- which makes it kind of a bear to edit, even as root.

this might be a challenge of ChromeOS not being able to handle the file system correctly. I don’t use ChromeOS, so might be wrong.

The original file is owned by user root

root@DietPiProd:~# ls -la /etc/wpa_supplicant/wpa_supplicant.conf
-rw------- 1 root root 219 Jun 17  2022 /etc/wpa_supplicant/wpa_supplicant.conf
root@DietPiProd:~#

The root account commonly uses the same UID 0 and GID 0 across Unix-like systems

root@DietPiProd:~# id root
uid=0(root) gid=0(root) groups=0(root)
root@DietPiProd:~#

Because so many tools, installers, and kernel components assume that UID 0 and GID 0 represent the superuser, nearly every mainstream distribution sticks to this.

usually root is able to edit everything, even files haven no permission (0000) at all

Unexpected indeed. The file is generated by this script when done via dietpi-wifi.txt preconfiguration or later via dietpi-config: DietPi/dietpi/func/dietpi-wifidb at 4471bf892e57845714b820f4f0df238f8a8f4392 · MichaIng/DietPi · GitHub

There you find:

G_EXEC chown root:root /var/lib/dietpi/dietpi-wifi.db /etc/wpa_supplicant/wpa_supplicant.conf
G_EXEC chmod 600 /var/lib/dietpi/dietpi-wifi.db /etc/wpa_supplicant/wpa_supplicant.conf

So while 0600 mode is expected, it should be owned by root then, or UID 0.

Does/did the file really have a different UID as owner, or does ChromeOS really map root differe tly?

That… I don’t know, beyond this is what I get when in the Terminal on my Chromebook:

memilanuk@penguin:/mnt/chromeos/removable/SD Card/etc/wpa_supplicant$ ls -al
total 48
drwxr-xr-x 2 nobody nogroup  4096 Sep 25 15:45 .
drwxr-xr-x 3 nobody nogroup    60 Sep 26 11:12 ..
-rwxr-xr-x 1 nobody nogroup   937 Aug  5  2024 action_wpa.sh
-rw-r--r-- 1 nobody nogroup 25569 Aug  5  2024 functions.sh
-rwxr-xr-x 1 nobody nogroup  4696 Aug  5  2024 ifupdown.sh
-rw------- 1 nobody nogroup   827 Sep 25 15:34 wpa_supplicant.conf
memilanuk@penguin:/mnt/chromeos/removable/SD Card/etc/wpa_supplicant$ less wpa_supplicant.conf 
wpa_supplicant.conf: Permission denied
memilanuk@penguin:/mnt/chromeos/removable/SD Card/etc/wpa_supplicant$ sudo less wpa_supplicant.conf 
wpa_supplicant.conf: Permission denied
memilanuk@penguin:/mnt/chromeos/removable/SD Card/etc/wpa_supplicant$ 

Can you try the -n flag with ls to show numeric user IDs instead of names? And id -u root to show the UID of the root user.

memilanuk@penguin:/mnt/chromeos/removable/SD Card/etc/wpa_supplicant$ ls -aln
total 48
drwxr-xr-x 2 65534 65534  4096 Sep 25 15:45 .
drwxr-xr-x 3 65534 65534    60 Sep 26 11:31 ..
-rwxr-xr-x 1 65534 65534   937 Aug  5  2024 action_wpa.sh
-rw-r--r-- 1 65534 65534 25569 Aug  5  2024 functions.sh
-rwxr-xr-x 1 65534 65534  4696 Aug  5  2024 ifupdown.sh
-rw------- 1 65534 65534   827 Sep 25 15:34 wpa_supplicant.conf
memilanuk@penguin:/mnt/chromeos/removable/SD Card/etc/wpa_supplicant$ id -u root
0
memilanuk@penguin:/mnt/chromeos/removable/SD Card/etc/wpa_supplicant$ 

or alternately:

memilanuk@penguin:/mnt/chromeos/removable/SD Card/etc/wpa_supplicant$ cat /etc/passwd | grep root
root:x:0:0:root:/root:/bin/bash
memilanuk@penguin:/mnt/chromeos/removable/SD Card/etc/wpa_supplicant$ cat /etc/passwd | grep nobody
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin

Looks like ChromeOS is doing some strange mount for the external drive, changing user IDs

Indeed confusing. I hope these IDs did not change permanently, but that this is some strange visual behavior of ChromeOS. nobody is intended to have absolutely no permission on anything aside of “others”. So a system where everything is owned by nobody is kinda compromised.

As near as I can tell, when I pop the sd card back in the RPi everything is as it should be, as far as permissions are concerned:

me@mashadar:/etc/wpa_supplicant$ ls -al wpa_supplicant.conf 
-rw------- 1 root root 567 Sep 25 15:53 wpa_supplicant.conf

me@mashadar:/etc/wpa_supplicant$ ls -aln wpa_supplicant.conf 
-rw------- 1 0 0 567 Sep 25 15:53 wpa_supplicant.conf

mounts can be given a uid=/gid= mount option, but AFAIK this does not recursively affect all contained files … never really used these :sweat_smile:.

How did you mount the drive? Just via `mount /dev/mmcwhatever /mnt/somewhere

… ah I see from the mountpoint above it seems to have been some GUI or other CLI method. Maybe this includes some mount options which intentionally prevent users from accessing root-owned files inside or so.

Hi all
Memilanuk have you try the command “chown” in the command line

chown root wpa_supplicant.conf

Guys we are moving away from the original issue that has been solved already.