This is a quick run down of the steps I like to take to initialize a fresh Raspberry Pi. Mostly so I can find it again later, but maybe you'll find it useful too.
Published
raspberry pilinux
This is a quick run down of the steps I like to take to initialize a fresh Raspberry Pi. Mostly so I can find it again later, but maybe you'll find it useful too.
The first step is downloading and writing an OS onto an SD Card so your device has something to boot from.
dd is colloquially known as 'disk destroyer' because if you're not careful you can write over your entire active disk destroying your system.. So be careful what you enter on the command line with dd!
Finally, once you have your SD card written, it will most likely mount the two new partitions automatically. You should see a ROOT and BOOT partition. If not, mount the BOOT partition briefly and navigate to it.
You can now add two small files to enable the SSH Server on boot, and connect to the wifi network of your choosing automatically. This way you never have to plug in a monitor / keyboard / mouse / etc.
The default credentials on a RaspiOS installation are: pi/raspberry
The very first thing you'll want to do, is update the apt cache and do an upgrade to get all the packages up-to-date from when the image was created until now.
bash
sudo apt update && sudo apt upgrade -y
Then, some of the first packages I like to install on a headless system include:
bash
sudo apt install -y net-tools vim git htop docker docker-compose software-properties-common build-essential zip unzip dnsutils
This will open a multi-step wizard which begins by asking for the new password. Then it asks for Fullname, City, State, etc. these fields I always leave empty.
You may also want to give your new user sudo permissions to be able to run 'sudo ..' commands.
Change to root with su and then execute:
bash
usermod -aG sudo [new username]
Now your new user will be able to run sudo .. commands with their new password.
You can set a new hostname via sudo hostnamectl set-hostname [name]. You may also have to adjust the local hosts file to set the new hostname as 127.0.0.1.
bash
sudo vim /etc/hosts
And adjust the lines for 127.0.0.1 and 127.0.1.1 to append your new hostname.
To copy our SSH key to your new raspberry pi, you can use ssh-copy-id. You can specify which key to install on the new device with the -i flag. From your main host (i.e. not the raspberry pi) run:
The latest version of Raspbian is based upon Debian 10 Buster. To set a static IP there, we'll want to use dhcpcd. This systemd service and config is started by default in Buster, we'll just have to adjust some config files.
bash
sudo vim /etc/dhcpcd.conf
There is a section around line 45 which is commented out describing how to setup a static ip. Simply uncomment this and provide the correct values for your network.
Once that is done, simply restart dhcpcd via systemctl
bash
sudo systemctl restart dhcpcd
It may hang for a minute, but should come right back up because it will have retained your old IP address as well until the next reboot. So for now the device will be reachable under the IP you initially SSHed into it with, and the new IP you just set as static. Upon your next reboot only the new IP should be available.