SSH key
- Git course
- Beginner
- Lesson 63/80
- 4 min
Learn to create an SSH key and add it to GitHub.
What Is an SSH Key?
An SSH key is a key pair used to authenticate securely between your computer and a remote server. This pair consists of a private key and a public key.
Private key --> Your computer
Public key --> GitHubThe private key is kept secret on your computer. The public key can be added to your GitHub account.
Generating Keys with ssh-keygen
ssh-keygen is a command-line tool used to generate an SSH key pair. When you run it, you can choose where to save the keys and optionally set a passphrase.
ssh-keygen -t ed25519 -C "ali@example.com"Ed25519 is an algorithm used for modern SSH keys. The file with the .pub extension is the public key.
Practice Prepare an SSH Key Generation Command
Store an SSH key generation command using the Ed25519 algorithm and an email comment in a JavaScript variable. The command must be ssh-keygen -t ed25519 -C "ali@example.com". Print the result.
Starter code
const sshCommand = "";
// Komutu yazdırSample solution
const sshCommand = 'ssh-keygen -t ed25519 -C "ali@example.com"';
console.log(sshCommand);Expected output
ssh-keygen -t ed25519 -C "ali@example.com"
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which SSH key should be added to your GitHub account?
- The passwords of both keys
- The Git configuration file
- The private key
- The public key Correct answer
Explanation: The public key is added to GitHub. The private key must remain on your computer and should never be shared.
2 Identify the Public Key File
ssh-keygen -t ed25519
cat ~/.ssh/id_ed25519____.pub
ssh-keygen -t ed25519
cat ~/.ssh/id_ed25519id_ed25519.pub
Explanation: When an Ed25519 key pair is generated, id_ed25519 is the private key and id_ed25519.pub is the public key file.
3 SSH Key Components
| Term | Meaning |
|---|---|
ssh-keygen |
Generates a key pair |
Private key |
The key that must remain secret |
Public key |
The key added to GitHub |
Ed25519 |
An SSH key algorithm |