SSH keys
Use SSH keys when connecting to a server. SSH keys are more secure than passwords.
Keys are a bit harder to setup, but very simple to use. Here's how to use keys on a Mac with code editor. First you need to create a key pair.
- On a Mac, open Terminal.
- Type
ssh-keygen
and press Enter. - When asked file to save and passphrase, just press Enter.
- Now keys have been created and stored in a
.ssh
folder.
On a Mac .ssh
folder is located at /Users/USERNAME/.ssh/
. Private key is called id_rsa
, public key is id_rsa.pub
. Private key stays on your device. Public pair must be copied to a remote server.
Go to .ssh
folder and open id_rsa.pub
in a text editor and copy the key.
- Connect to server using a password.
- Find folder
.ssh
, it's usually on a root. - Look for file
authorized_keys
. - If folder and file doesn't exist, you need to create one.
- Open
authorized_keys
file and paste public key onto the end of that file. Other keys may already be there.
Finally you need to tell your code editor to use key instead of password.
- Open code editor.
- In server settings, remove the password and click key icon next to it.
- Ask to authenticate with key you just created.
You can use same key pair to connect different servers. SSH connection can come only form the device where the private key is located.