Securing your connection to code repositories is paramount. GitHub offers SSH keys as a robust, passwordless authentication method. This process involves generating a unique pair of cryptographic keys on your local machine: a private key that remains confidential and a public key distributed to services like GitHub. When you initiate an action, such as pushing or pulling code, your local machine uses the private key to cryptographically prove your identity to GitHub, which verifies it against the stored public key. This ensures only you can interact with your repositories.
Generating and Adding Your SSH Key
To begin, open your terminal and generate a new SSH key pair using the command ssh-keygen -t ed25519 -C "[email protected]", replacing the placeholder with your GitHub-associated email. Accept the default file location by pressing Enter, and then set a strong passphrase for added security. The system will not display your passphrase as you type.
Next, add your SSH key to the ssh-agent, a program that manages your keys and avoids repeated passphrase entries. Execute ssh-add ~/.ssh/id_ed25519, entering your passphrase when prompted.
To get the public key content for GitHub, run cat ~/.ssh/id_ed25519.pub in your terminal. Copy the entire output.
Navigate to your GitHub account settings. In the left-hand sidebar, select 'SSH and GPG keys'. Click the 'New SSH key' button. Provide a descriptive title for your key (e.g., 'work-laptop') in the 'Title' field and paste the copied public key into the 'Key' box. Finally, click 'Add SSH key'.
