I recently got a new Pi Zero W for a smart home project and I'd like to set it up for SSH without getting micro adapters for display, keyboard, etc. I currently have a Pi 3 and I was wondering whether I could just change out the SD cards. Would the SD card retain the WiFi credentials and have the same IP address? If so it would make my life a lot easier.
Here is how to enable SSH and go headless:
- Shut down the Raspberry Pi
- Remove the SD card and plug into a linux / windows machine
- mount the /boot partition
- in /boot create an empty file named "ssh" or "ssh.txt"
- unmount the /boot partition
- Plug it into Raspberry Pi and boot it
- Use your router's DHCP allocation table or use nmap to find the IP address of your Pi
- ssh into the pi as user (pi for new system)
For a new system you would have to create a wpa_supplicant.conf file in /boot to configure your wifi. Follow this post for a new setup.
You can change the SD Card of UP TO DATE Raspbian images between ALL models.
Pi Zero W indeed started life as a copy of my Pi3 card.
HOWEVER there are caveats;
This assumes you are running a default setup
You will potentially have problems if you run multiple systems with the same
Bluetooth pairings are not transferrable, due to different MAC and you cannot pair the same peripheral to different PI (although I have configured my OS in multiple Pi so all have the similar settings).
It is possible to configure the OS so that this will not work, but it is impossible to know.
You will NOT in general have the same IP address (which would be a disaster), however this is a function of your DHCP server, which will in general assign a new address, based on MAC.
All my Pi use identical
Indeed they use identical
config.txt files, although I use conditional settings to accommodate different peripherals (such as RTC).