Getting Started SSH Keys
SSH Keys
Learn how SSH keys provide secure authentication for remote Git repositories and how to manage them.
SSH keys provide a secure way to authenticate to remote Git repositories without typing your password for every operation.
Instead of sending a password over the network, SSH uses cryptographic keys to prove that your machine is allowed to access the remote service.
SSH key basics
SSH authentication uses a keypair:
- a private key stored on your local machine, such as
~/.ssh/id_ed25519 - a public key added to a Git hosting service such as GitHub
The .pub extension indicates that a key file is the public key. For example, ~/.ssh/id_ed25519.pub is the public key that corresponds to ~/.ssh/id_ed25519.
The private key should stay only on devices you trust.
The public key can be shared with the Git service you want to authenticate against.
Managing SSH keys
View your keys
Start by checking whether you already have SSH keys on your machine.
On most systems, SSH keys are stored in the ~/.ssh/ directory.
Each key shows:
- Key type (
Ed25519,RSA,ECDSA) - Comment or name
- Fingerprint
Generate a new key
Generate a new key when you do not have one yet or when you want a separate key for a different machine or account.
Ed25519 is a common modern default for Git authentication.
ssh-keygen -t ed25519 -C "your_email@example.com"Import an existing key
If you already have an SSH keypair from another setup, you can import it instead of creating a new one.
Make sure the private key stays secure and that the matching public key is added to the Git service you use.
cp /path/to/id_ed25519 ~/.ssh/id_ed25519
cp /path/to/id_ed25519.pub ~/.ssh/id_ed25519.pub
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pubCopy the public key
When a Git hosting service asks for your SSH key, it expects the contents of the public key file.
cat ~/.ssh/id_ed25519.pubExport a key
Export a key only when you need to move it to another trusted system or create a backup.
Treat exported private keys as sensitive secrets.
cp ~/.ssh/id_ed25519 /path/to/backup/id_ed25519
cp ~/.ssh/id_ed25519.pub /path/to/backup/id_ed25519.pubDelete a key
Delete keys you no longer use, especially if a device has been retired or access should be removed.
When deleting a key, also remove the corresponding public key from any Git hosting services where it was registered.
rm ~/.ssh/id_ed25519 ~/.ssh/id_ed25519.pub