Skip to content

Instantly share code, notes, and snippets.

@mohamedaboelmagd
Created October 11, 2017 08:46
Show Gist options
  • Save mohamedaboelmagd/306b54c8149f046f7a84e8fe96a39b5e to your computer and use it in GitHub Desktop.
Save mohamedaboelmagd/306b54c8149f046f7a84e8fe96a39b5e to your computer and use it in GitHub Desktop.
Generating a new SSH key and adding it to the ssh-agent
Generating a new SSH key
Open Terminal.
Paste the text below, substituting in your GitHub email address.
> ssh-keygen -t rsa -b 4096 -C "[email protected]"
This creates a new ssh key, using the provided email as a label.
Generating public/private rsa key pair.
When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.
Enter a file in which to save the key (/home/you/.ssh/id_rsa): [Press enter]
At the prompt, type a secure passphrase. For more information, see "Working with SSH key passphrases".
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
Adding your SSH key to the ssh-agent
Before adding a new SSH key to the ssh-agent to manage your keys, you should have checked for existing SSH keys and generated a new SSH key.
Start the ssh-agent in the background.
> eval "$(ssh-agent -s)"
Agent pid 59566
Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsa in the command with the name of your private key file.
> ssh-add ~/.ssh/id_rsa
Add the SSH key to your GitHub account.
Copy the SSH key to your clipboard.
If your SSH key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don't add any newlines or whitespace.
>$ sudo apt-get install xclip
# Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`)
>$ xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
Paste your key into Github SSH keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment