ssh-keygen -t rsa -C "MyEmailAddress" -f ~/.ssh/id_rsa -P ""
Then any ssh command will use by default that key.
ls -al ~/.ssh
Check the directory listing to see if you already have a public SSH key. By default, the filenames of the public keys are one of the following: id_xxxx.pub (ex: id_rsa.pub). If you don't have an existing public and private key pair, create one using this command:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
This creates a new ssh key, using the provided email as a label. When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location. At the prompt, type a secure passphrase.
If you see an existing public and private key pair listed that you would like to use to connect to GitHub, or once you are done with the above key generation step, you can add your SSH key to the ssh-agent with the following commands:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa (Add -K option, if on MAC OS, as it will add the passphrase in your keychain when you add an ssh key to the ssh-agent.)
Source: https://docs.github.com/
This happened to me when I was simply in a directory other than the one where the SSH key was.
In order to fix this: you need to check the path to the directory where the SSH key was saved. Scroll up to where you created the key and you should see:
Your public key has been saved in /Users/userlocation/.ssh/id_rsa.pub
Now check your working directory:
If your working directory is different from the one that holds the SSH key, change the directory:
cd /Users/userlocation #find yours!
and then run the command (slightly changed):
cat .ssh/id_rsa.pub
This worked for me! (Remember to run ssh-keygen
first!)
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.