Setting up SSH key authentication on your server will allow you to log in to your server without typing your password. This page shows you how to set it up.
SSH keys come in a pair. One is your private SSH key, and one is your public SSH key. They both have the same base name, but the public key ends with “.pub”.
Step 1 – Open your terminal
Windows
If you’re on a Windows computer, make your life easier and install Git BASH. It comes as part of Git for Windows. To open Git BASH, their instructions say this:
Once downloaded, find the included .exe file and open to execute Git Bash.
Mac or Linux
If you’re on Mac or Linux, open your Terminal.
Step 2 – Create SSH Keys
Do this in Git Bash (on Windows) or your Terminal (on Linux or Mac):
Make sure you’re in your home directory. If you’re ever unsure if you’re in your home directory, type cd
and then press Enter
. That will put you in your home directory on your computer.
Change to your local home directory:
cd
Create your key pair:
ssh-keygen -t rsa -b 4096
It will ask you to “Enter file in which to save the key.”
You can leave it as is, with the default filename usually being “id_rsa” id the folder named “.ssh”:
.ssh/id_rsa
That will be the name for your private key. You can just press Enter to continue. (Or, you can first change the file name from “id_rsa” to whatever name you want.)
It will then ask you to “Enter passphrase (empty for no passphrase).” If you choose to leave it empty, you must still press Enter
. If you choose to enter a passphrase for more security, you must remember to save that in a secure place.
Once complete, it will output two files:
id_rsa
— the private keyid_rsa.pub
— the public key
These files will be stored in your user folder, such as:
C:\Users\your_username\.ssh\id_rsa.pub
Once the key is saved, tighten permissions for the key (if you replaced “id_rsa” with your own private key name, replace it in the following command):
chmod 600 .ssh/id_rsa
Note
The private key remains stored on your computer and is not copied to the server.
Only the public key is copied to the server. The public key ends with .pub
Extra Reference
See how to copy your SSH public key to your server.
Coming Up Next
In the next tutorial: add your public key to your Vultr account.
Questions and Comments are Welcome