Username and passwords are archaic and pose significant security concerns. Generating public and private SSH key pair provides you with two long strings of characters. The public key is placed on your server, and it's unlocked by connecting with the local private key.
Open a terminal on your workstation and use the ssh-keygen
command to generate a new key. Specify the -C flag to add a comment with your username.
where:
[KEY_FILENAME]
is the name that you want to use for your SSH key files. For example, a filename ofmy-ssh-key
generates a private key file namedmy-ssh-key
and a public key file namedmy-ssh-key.pub
.[USERNAME]
is the username for the user connecting to the instance.
This command generates a private SSH key file and a matching public SSH key (at ~/.ssh/[KEY_FILENAME].pub
) with the following structure:
ssh-rsa [KEY_VALUE] [USERNAME]
Where:
[KEY_VALUE]
is the key value generated byssh-keygen
. It is a long string of characters.[USERNAME]
is the user that created the key. You can modify this value to be more descriptive.
Restrict access to your private key so that only you can read it, and nobody can write to it.
chmod 400 ~/.ssh/[KEY_FILENAME]
Where [KEY_FILENAME]
is the name that you used for your SSH key files.
Repeat this process for every user who needs a new key. Then, locate the public SSH keys that you made and any existing public SSH keys that you want to add to a project or instance.