SSH keys
- Git course
- Expert
- Lesson 26/32
- 4 min
Learn SSH key management.
How SSH keys work
SSH allows you to authenticate with remote Git servers using a key pair instead of a password. The private key stays secret on your computer, while the public key is added to services such as GitHub.
ssh-keygen -t ed25519 -C "developer@example.com"Ed25519 is a modern algorithm used to generate SSH keys. You should never share your private key.
Managing keys with SSH agent
SSH agent manages private keys in memory and reduces the need to enter the key passphrase for every connection. You can use the ssh-add command to add your key to the agent.
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
ssh-add -lThe ssh-add -l command lists keys managed by the agent. It is also important to keep key file permissions restricted.
Practice Add an SSH key to the agent
Start the SSH agent, add the ~/.ssh/id_ed25519 private key to the agent, and list the managed keys. Print a completion message at the end of the commands.
Starter code
# SSH agent'ı başlat
# Anahtarı ekle ve listeleSample solution
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
ssh-add -l
echo "SSH anahtar yönetimi tamamlandı."Expected output
SSH anahtar yönetimi tamamlandı.
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which key in an SSH key pair can be shared and added to the server?
- GPG secret key
- Session password
- Public key Correct answer
- Private key
Explanation: The public key is added to the server. The private key must remain protected on the user's device.
2 Choose the SSH key algorithm
ssh-keygen -t ____ -C "developer@example.com"
ssh-keygen -t ed25519 -C "developer@example.com"
Explanation: <code>ed25519</code> is an algorithm used to generate an SSH key pair.
3 SSH key management
| Term | Meaning |
|---|---|
Private key |
Key kept secret on the device |
Public key |
Key added to the remote service |
SSH agent |
Manages private keys during a session |
Passphrase |
Password protecting a private key |