Tips for Managing Your Raspberry Pis
Here are three simple tips for making your life a little easier while managing Raspberry Pis running 20.04 (and some older versions - post 18.04 I believe for netplan config.)
Change the Hostname
Just edit the file!
## Edit a file - simple!
sudo nano /etc/hostname
Configure a Static IP Address
By editing this file you can configure a static IP address. As per usual, be careful with the spacing!
cd /etc/netplan/
ls
## Listing
50-cloud-init.yaml
## Edit this file.
sudo nano 50-cloud-init.yaml
## This is the configuration
network:
ethernets:
eth0:
addresses: [10.11.11.111/24]
gateway4: 10.11.11.1
nameservers:
addresses: [10.11.11.15, 4.2.2.2]
version: 2
Once completed, apply your changes.
sudo netplan apply
## Or restart to apply all your changes.
sudo reboot
Using SSH Key to Access Raspberry Pis
So, simple!
Start from your host machine and then copy the ssh-copy-id command to copy the key onto the destination machine.
## Generate the key pair.
ssh-keygen
## follow the steps, enter a paraphrase if you choose (highly suggested)
## copy the key!
ssh-copy-id <user>@<ip address>
## You can now login with <user>@<ip address>
Disabling SSH Password Access
Since we have the key pairs set up, we can disable password access to the boxes. I would suggest only doing this if you have another means (if a cloud or VPS server, another GUI login or physical access) to access the machine in a worst case scenario.
If the above SSH key commands worked correctly, you simply have to disable password authentication in the ssh config file.
/etc /ssh /sshd_config # spaces are for security purposes I assume.
## In this file comment out the below line
PasswordAuthentication yes
## It should end up looking like this.
#PasswordAuthentication yes
## Finally restart the SSH service, and log back in.
service ssh restart
These few tips are quick and help administrative your Pis a whole lot easier. Using ssh keys literally saves you half the time when logging in :).
The biggest benefit would have to be automation and scripting. Your passwords are not required in your scripts. They will be transferable from machine to machine as long as the executing hosts are known.