How to Change Raspberry Pi Wi-Fi Details From the SD Card

Wait 5 sec.

If your Raspberry Pi can no longer connect to Wi-Fi because the SSID or password changed, you can update the Wi-Fi configuration directly from its SD card. This helps when you cannot connect the device to a monitor and keyboard.That's what I did. I had switched to a different internet provider, and that changed the router, its SSID and the password. I was using a Raspberry Pi Pico W in my Pi Dog. Connecting it to a screen and keyboard would have been a pain.The easier option was to just take out the SD card and edit the WiFi details directly there. The entire process is composed of the following step:Insert the SD card with Raspberry Pi OS on it on your (Linux) computerGo to the mounted rootfs partition and go to /etc/NetworkManager/system-connections/ locationHere, either create or edit .nmconnection file and enter the wifi name (SSID) and passwordLet me show that in detail for you.🚧Older Raspberry Pi OS releases may use wpa_supplicant.conf instead of NetworkManager. In that case, this method may not entirely be applicable. I have tested it on Raspberry Pi 5 running Raspberry Pi OS based on Debian Trixie.Step 1: Connect the SD card to your computerShut down the Raspberry Pi, remove the microSD card, and insert it into your Linux laptop or desktop using an SD card reader.Raspberry Pi OS usually has two partitions:bootfsrootfsThe Wi-Fi configuration is stored inside the rootfs partition.Step 2. Find the SD card mount pointsOpen a terminal and run:lsblk -fYou should see something similar to:sda├─sda1 vfat FAT32 bootfs B2F0-82D2 438.1M 13% /run/media/abhishek/bootfs└─sda2 ext4 1.0 rootfs 15f4c6be-1102-4331-9904-f78e78afd1fd 21.9G 18% /run/media/abhishek/rootfsIf you only see bootfs, mounted, you can mount rootfs from the file explorer.As you can see, for me, the Raspberry Pi root filesystem is available at:/run/media/abhishek/rootfsYou can also confirm it with:mount | grep rootfs/dev/sda2 on /run/media/abhishek/rootfs type ext4 (rw,nosuid,nodev,relatime,errors=remount-ro,uhelper=udisks2Step 3. Check the existing Wi-Fi configurationRecent Raspberry Pi OS releases store NetworkManager connection profiles here:/etc/NetworkManager/system-connections/🚧Make sure to use your own username and the correct path of rootfs and files by replacing them in the command examples. You can also keep on using $USER as this environment variable automatically uses your username.Since we are accessing Raspberry Pi OS through its SD card, run:sudo ls -la /run/media/$USER/rootfs/etc/NetworkManager/system-connections/If you already see a .nmconnection file, you can edit that file. No nmconnection file? Create oneIf the directory is empty, create a new Wi-Fi profile.touch /run/media/$USER/rootfs/etc/NetworkManager/system-connections/home-wifi.nmconnectionAnd then use a terminal-based text editor like Nano or even Micro and add the following details:🚧In the text below, change the value of ssid and psk with your wifi access point name and its password.[connection]id=home-wifitype=wifiinterface-name=wlan0autoconnect=true[wifi]mode=infrastructuressid=YOUR-WIFI-SSID[wifi-security]key-mgmt=wpa-pskpsk=YOUR-WIFI-PASSWORD[ipv4]method=auto[ipv6]method=autoEOFStep 4. Set the correct file permissionsYour work is almost done. You just need to set correct file permissions. That's because NetworkManager expects connection files to be readable only by root.To give it the correct file permissions, use the following command:sudo chmod 600 /run/media/$USER/rootfs/etc/NetworkManager/system-connections/home-wifi.nmconnectionVerify the permissions:sudo ls -l /run/media/$USER/rootfs/etc/NetworkManager/system-connections/The file should look something like:-rw------- 1 root root ... home-wifi.nmconnection📋Before going further, double ensure that you have used the correct WiFi SSID and the password. Any typo and you will have to repeat the process. You won't want that to happen.Step 5. Flush the changes to the SD card before removingThis is an important step. After making all the changes, run this command:syncThe sync command makes sure any pending writes cached in memory are actually written to the SD card.And then you can either unmount from the file explorer or use the umount command for both partitions:sudo umount /run/media/$USER/rootfssudo umount /run/media/$USER/bootfsYou can now safely remove the SD card.Step 6. Verifying the connectionInsert the card back into the Raspberry Pi and power it on. After it boots, check the devices connected on your network to find the Raspberry Pi's IP address. The simplest way would be to log in to your router and see the connected devices.Otherwise, Angry IP Scanner is a good graphical tool for scanning your network. Command line tool nmap also does the job:sudo nmap -sn 192.168.0.0/24Normally, it should show your Raspberry Pi's hostname. You can also try to run scan before turning on Pi and a few minutes after turning it on. This should show the new devices that turn up between the two scans.Finally, check the connectivity with:ping RASPBERRY_PI_IPOr, if SSH is enabled on your Raspberry Pi, connect to it:ssh username@RASPBERRY_PI_IPBy the way, if you have forgotten the user password of your Raspberry Pi, that can be easily reset too. Enjoy your Raspberry Pi 😄