To generate a new SSH key and add it to the ssh-agent, follow these steps:
- Generate a new SSH key: Open your terminal or command prompt and enter the following command: cssCopy
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Replace"your_email@example.com"
with the email address associated with your GitHub account. Press Enter to accept the default file location and optionally set a passphrase for added security. - Start the ssh-agent (if not already running): If you are using a Linux or macOS system, you can start the ssh-agent by running the command: bashCopy
eval "$(ssh-agent -s)"
For Windows users, you can start the ssh-agent using: javascriptCopyeval `ssh-agent -s`
- Add your SSH private key to the ssh-agent: Use the command below to add your SSH private key to the ssh-agent: bashCopy
ssh-add ~/.ssh/id_rsa
Replaceid_rsa
with the name of your private key file if it’s different. - (Optional) Verify that the SSH key is added: You can verify that your SSH key is added to the ssh-agent by listing the keys using: csharpCopy
ssh-add -l
- Add the SSH key to your GitHub account: Copy the SSH public key to your clipboard using the command: bashCopy
pbcopy < ~/.ssh/id_rsa.pub
For Windows users, you can use: bashCopyclip < ~/.ssh/id_rsa.pub
Next, go to your GitHub account settings > SSH and GPG keys > New SSH key. Paste the copied SSH key into the “Key” field and give it a descriptive title. Click “Add SSH key” to save it.
Now, your new SSH key is generated, added to the ssh-agent, and linked to your GitHub account for authentication. You can use this SSH key to securely connect to GitHub repositories using Git and SSH.