Raspberry Pi and SSH: How-to Setup a Headless Machine (No Monitor) and Pasword-less Logins
SSH is the staple of any remote access setup. Setting it up on the Raspberry Pi (RPi) is ideal since the device is so small. Instead of hooking it up to a monitor, keyboard, and mouse, it is much better to simply access it remotely from another computer. Having the ability to not type in a password will also make life much easier.
Requirements For This Walkthrough
- Mac running OS X
- Raspberry Pi running Raspbian “wheezy”
- Ethernet cable(s) or Wi-Fi
- Homebrew (optional)
- nmap via Homebrew (optional)
- iNet Pro (for iOS)
- AngryIP Scanner (optional)
- Any other sort of network scanner that will provide IPs of devices on the network
Knowledge, Skills, and Abilities
- Ability to navigate throughout a computer OS
- Knowledge of basic computer terminology
- Knowledge of IP addresses
- Ability and confidence to enter commands in Terminal (modifying them to suit your environment)
Find the IP of the RPi Using nmap, AngryIP Scanner, or Another Device
In order to set up a Raspberry Pi that does not have a monitor, keyboard, or mouse, it is necessary to find the IP address so it can be configured from a different computer via SSH. There are a few options for this (order of most-useful and easiest-to-install to the least effective)
Find the Pi’s IP address using nmap from the command line:
- Connect your iDevice to the network
- Scan the network using iNet Pro
This method is the least effective since you only will be able to see the IP address and not any information about what device is what.
- Scan the network using AngryIP Scanner
- Try logging into each active IP address using the steps below using the process of elimination
SSH into the RPi Once You Know It’s IP Address
From Terminal, you need to log into the Pi
log in using the default password of raspberry .
Update the Pi Before Doing Anything Else
sudo apt-get update sudo apt-get upgrade
Run raspi-config to Set Common Options
Enable the following settings
Expand file system Change user password Set a hostname Enable SSH
Reboot to Apply All Changes
Generate SSH Keys on Your Mac (Not the RPi) For Password-less Logins
First, generate a private/public pair of SSH keys.
ssh-keygen -t rsa cat ~/.ssh/id_rsa.pub | ssh pi@<ip_address_of_raspberry_pi> "mkdir .ssh;cat >> .ssh/authorized_keys"
Replace <ip_address_of_raspberry_pi> with the IP address of the RPi. This command will copy the public key generated on the Mac into the authorized_keys file on the Pi. You will need to enter the password of the pi user to execute this command. If you try to SSH into the machine after this command, no password will be required.
If the RPi will be accessible over the Internet, some safeguards should be taken to secure the device.
sudo vi /etc/ssh/sshd_config
Change the following settings to no, uncommenting if necessary.
PermitRootLogin No PasswordAuthentication No
Alternatively, you could also change the port to a different number for a little security by obscurity.