"Server" refers to the computer you are trying to connect to. (Ex. Raspberry Pi)
"Client" refers to the computer you are connecting from. (Ex. Desktop PC)
If you have not generated a private and public key, known as a key pair previously on this computer then follow these instructions. Otherwise skip to the On the Sever Machine section.
- Open the Terminal application or Windows PowerShell
- Create a SSH keypair by running the code contained in the block below (note: the program will prompt you several times - use the defaults by typing the "enter" key):
ssh-keygen -t ed25519
- Enter the passphrase to encrypt the private key. Re-enter the same passphrase and press Enter to finish generating the key pair.
- Copy the public key file that was created in the
.ssh
directory in your user account (the file should be named:id_ed25519.pub
). This key will be added to the sever machine in the following steps.
- Install OS on Raspberry Pi
- Boot it up and connect to internet
- Open the Terminal application
- Create a
.ssh
directory in the user's home directorymkdir -m 700 ~/.ssh
- Within the
.ssh
directory create a file namedauthorized_keys
touch ~/.ssh/authorized_keys
- Open the
authorized_keys
file using a text editor such as Text Editor, Notepad or VIM. Paste the client public key into theauthorized_keys
file as a new line. Save the file and closevim ~/.ssh/authorized_keys
- Change the permissions on
authorized_keys
so that the user can only read and writechmod 600 ~/.ssh/authorized_keys
- Copy the server public key in the directory
/etc/ssh/ssh_host_ed25519_key.pub
. Can use the commandcat
to print key to the terminal as shown belowcat /etc/ssh/ssh_host_ed25519_key.pub
- Find a way to send this public key to your client computer, for example with a USB Flash Drive, email, messaging app
- Determine the Server IP address. You can use the command
hostname -I
- To enable SSH on Raspberry Pi
- Select the Raspberry Menu Icon
- Select Preferences > Raspberry Pi Configuration
- Click the Interfaces tab
- Click the Enabled radio button for SSH
- In the
.ssh
directory, create a file calledknown_hosts
. Note that it has no file extension. Edit theknown_hosts
file using a text editor and paste the public key of the server into this file. Save the file and closevim ~/.ssh/known_hosts
- In terminal or Windows PowerShell enter the command
ssh [user]@[sever IP]
- The connection will prompt for the ssh keypair password created earlier
Once the connection is established, you can manage the server remotely from your computer. :)