SSH keys are a form of identification that the Secure Shell (SSH) protocol uses to securely connect to remote servers. Here's how to use SSH keys.
-
Open a terminal.
-
Run the following command to generate a new SSH key:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Replace "[email protected]" with your email address.
-
When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.
-
At the prompt, type a secure passphrase.
-
Start the ssh-agent in the background:
eval "$(ssh-agent -s)"
-
Add your SSH private key to the ssh-agent:
ssh-add ~/.ssh/id_rsa
-
Copy your SSH public key to your clipboard:
clip < ~/.ssh/id_rsa.pub
On Linux, you can use xclip:
```bash
xclip -sel clip < ~/.ssh/id_rsa.pub
```
- On the server you want to connect to, open the
~/.ssh/authorized_keys
file in a text editor and paste your public key on a new line.
You can now connect to the server with:
```bash
ssh user@hostname
```
Replace user
with your username on the server and hostname
with the hostname of the server. Because you've added your SSH key to the ssh-agent, you shouldn't have to enter your passphrase every time you connect.