On your local machine (which you will access your remote server from)
1. Run:
ssh-keygen (and the following configurations are guided)2. Configure your config file (~/.ssh/config) with your created public key directory location, for example:
Host 192.168.0.2 # your rpi ip address
HostName 192.168.0.2 # your rpi ip address
User pi
IdentityFile ~/.ssh/yourkey
3. After done creating public key, copy your public key file content| Example content of public key file |
cat ~/.ssh/yourkey.pub | pbcopy (for mac OS)
On raspberry pi (remote server)
3. Paste the copied content from step 2 into ~/.ssh/authorized_keys (it is the directory by default) or append to the file if existing content available.
Learning source: How to set up ssh so you aren't asked for a password