This repository has been archived by the owner on Sep 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Set up Raspberry Pi to connect through SSH
Robert Fairley edited this page Mar 9, 2019
·
1 revision
- Set up Raspberry Pi as per https://www.raspberrypi.org/help/noobs-setup/2/
- After the OS is installed on the Pi, type in the terminal
ifconfig
. - Note down the IP address shown under
wlan0:
inet
. We will use this IP address in a later ssh command. - On your laptop, if you are on Linux, type type
cat ~/.ssh/id_rsa.pub
to output your PC's public SSH key. If the file does not exist, then generate a public/private SSH key pair by typingssh-keygen
in the terminal. You can write the keys to the default location the prompt suggests, and you can either set or not set a password. Once generated, run the previouscat
command. - Copy the output of the
cat
command in step 4. - Now we need to write to the public key which we just copied to a line in a file,
~/.ssh/authorized_keys
on the Raspberry Pi. This will allow us to authenticate using SSH public key rather than password, which is done by pairing keys inauthorized_keys
with your private key (~/.ssh/id_rsa
) on your laptop. If a pair is found, then the Raspberry Pi knows that it is your laptop trying to log into it, and your laptop is authenticated. To copy the key over, I opened up a new etherpad. Paste what was copied in Step 5) into the etherpad. What you pasted should look like this:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDWUy47psZpehag0dLoJZW4pFEHRJ7LtwUgVXBtFwFWvAziGRdo3vT/jSCPTig9NikY//HjHEy7eR5jUcDbz6vcj3Fz1vq8dP06DAKLr7XJPAYQTHSFrKT2yjnrXzqm0WhE9LVY9GTBJGdy4VOvus5YcXQvK7tFgw4fdk1PlgcTdMXo53UxObeRpML8gMnhT0yMS2mF06VRlzLy9rBs41wqjAwdyThBRBBB8FLwZY2+mCq7PJWYE8gjSb/neFHB/vHwfmNHuL3H/kRerBx6Y9VKd0mgRvsDu5ha7tINPXiHLqGTCzCWuQc9QCuKADsGciy6sxvDWST2PRE+7MD+8FMZ rob@LAPTOP-9PECVDPO
- In the Raspberry Pi, logged in as the
pi
user, go to the URL of the etherpad you pasted the key in. Copy the key, and add it in a new line to~/.ssh/authorized_keys
. Ifauthorized_keys
does not exist, create it. - Save the
~/.ssh/authorized_keys
file. - Now from your laptop, do
ssh pi@<ip address you noted in step 3>
. As an example, this looks likessh pi@100.65.181.17
. You might be prompted for the password of your SSH key if you set it in step 4). Now you should be logged in and will see output like:
Linux raspberrypi 4.14.98-v7+ #1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Tue Nov 13 14:25:00 2018
pi@raspberrypi:~ $
Now you don't need the GUI, and can SSH login as long as you know the IP of the Pi!