Can't push to GitHub after enabling two factor auth [duplicate] - github

I generated an SSH key pair without a password and added the public key to GitHub.
Connection with
user#dev:/var/www/project# ssh -T git#github.com
Hi User! You've successfully authenticated, but GitHub does not provide shell access.
was successful and when I rename the key, it fails.
But when I want to push my changes, it stills ask me for my username and password combination.
Is there a way to push without a password?

If it is asking you for a username and password, your origin remote is pointing at the HTTPS URL rather than the SSH URL.
Change it to ssh.
For example, a GitHub project like Git will have an HTTPS URL:
https://github.com/<Username>/<Project>.git
And the SSH one:
git#github.com:<Username>/<Project>.git
You can do:
git remote set-url origin git#github.com:<Username>/<Project>.git
to change the URL.

In case you are indeed using the SSH URL, but still are asked for username and password when git pushing:
git remote set-url origin git#github.com:<Username>/<Project>.git
You should try troubleshooting with:
ssh -vT git#github.com
Below is a piece of sample output:
...
debug1: Trying private key: /c/Users/Yuci/.ssh/id_rsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_dsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
I actually have already added the public key to GitHub before, and I also have the private key locally. However, my private key is of a different name called /c/Users/Yuci/.ssh/github_rsa.
According to the sample output, Git is trying /c/Users/Yuci/.ssh/id_rsa, which I don't have. Therefore, I could simply copy github_rsa to id_rsa in the same directory.
cp /c/Users/Yuci/.ssh/github_rsa /c/Users/Yuci/.ssh/id_rsa
Now when I run ssh -vT git#github.com again, I have:
...
debug1: Trying private key: /c/Users/Yuci/.ssh/id_rsa
debug1: Authentication succeeded (publickey).
...
Hi <my username>! You've successfully authenticated, but GitHub does not provide shell access.
...
And now I can push to GitHub without being asked for username and password :-)

As usual, create an SSH key and paste the public key to GitHub. Add the private key to ssh-agent. (I assume this is what you have done.)
To check everything is correct, use ssh -T git#github.com
Next, don't forget to modify the remote point as follows:
git remote set-url origin git#github.com:username/your-repository.git

Additionally for gists, it seems you must leave out the username
git remote set-url origin git#gist.github.com:<Project code>

You have to use the SSH version, not HTTPS. When you clone from a repository, copy the link with the SSH version, because SSH is easy to use and solves all problems with access. You can set the access for every SSH you input into your account (like push, pull, clone, etc...)
Here is a link, which says why we need SSH and how to use it: step by step
Git Generate SSH Keys

for using SSH you must use $ git remote add origin git#github.com:USERNAME/REPOSITORY.git instead of git remote add origin remote_repository_URL.
you can check it with $ git remote -v, if you see 2 lines in the below format, it will work correctly:
origin git#github.com:username/repo-name.git (fetch)
origin git#github.com:username/repo-name.git (push)

Like the other users mentioned, you must convert it from using HTTPS to SSH. I don't see an answer with an end-to-end solution. After setting up the ssh keys, do (on your local machine) :
$ git remote set-url origin git#github.com:username/your_repo.git # Convert HTTPS -> SSH
$ ssh-add ~/.ssh/id_rsa_github # add private github ssh key ssh-agent (assuming you have it already running)
$ git push

You did everything ok but git still asking by password, this worked for me, execute the next commando in your current project's path:
~ ssh-add -K ~/.ssh/id_rsaYourIdRsa
Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsaYourIdRsa in the command with the name of your private key file.

Using the command line:
Enter ls -al ~/.ssh to see if existing SSH keys are present.
In the terminal is shows: No directory exist
Then generate a new SSH key
Step 1.
ssh-keygen -t rsa -b 4096 -C "your_email#example.com"
step 2.
Enter a file in which to save the key (/Users/you/.ssh/id_rsa): <here is file name and enter the key>
step 3.
Enter passphrase (empty for no passphrase): [Type a password]
Enter same passphrase again: [Type password again]

Related

Github: I have to make a new SSH key after every use

I have a school and a personal Github, so I made an SSH key for my personal account and linked it up. It always works only once, then gives me
Push Failed
Git#github.com: Permission denied (publickey). Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
It works fine again after I delete the old SSH and make a new one, but this is obviously a huge hassle. I am on Windows 10, using Git Bash, and IDE is IntelliJ.
Any ideas? Thanks.
I solved this problem in the following way:
1.Create a file named config in the path $USER_HOME/.ssh/, then add following content.
# For school account
Host school_github
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_school
# For personal account
Host personal_github
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_personal
2.Run following command using git bash:
Change your school github repository configuration
git remote rm origin
git remote add origin git#school_github:your_github_username/your_repo_name.git
You can hava a try.
You don't need to create SSH keys for each git service just upload the same public key to both personal and school accounts and it will work.
SSH public key is tied to you local account you have generate SSH keys only if you are using different local(machine) account or different machine
Seems to me like when you try to authenticate, you are probably not using your keys.
If you run the command
ssh-add -l
You (should) see a list of all your keys. Each time you start a new session, make sure to start up the agent and add your keys.
eval `ssh-agent`
ssh-add ~/.ssh/id_rsa

Error "The authenticity of host 'github.com' can't be established. RSA key fingerprint "

I use my project at work, but I would like to work with him from home as I can log into my home machine to work with my project.
However, from home, I see the following message:
The authenticity of host 'github.com (ip)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)?
How can I get past it?
You should simply be able to answer 'yes', which will update your ~/.ssh/known_hosts file.
A better approach, to avoid any MITM (Man-In-The-Middle) attack, would be (as commented below by Mamsds) to verify Github's public key first (see "GitHub's SSH key fingerprints") and, if you find a match, then you can answer 'yes'.
Example:
ssh-keyscan -t ecdsa github.com 2>&1 |ssh-keygen -lf -
256 SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM github.com (ECDSA)
After that, you can use a GitHub SSH URL (provided you have generated the SSH public/private keys, and registered the public one to your GitHub profile)
Note: the ssh key generation should use the base64 old PEM format (option -m PEM), rather than the new current 70 chars OpenSSH one.
See "What is the correct format for private key in Credentials":
ssh-keygen -m PEM -t rsa -P "" -f afile
That or you can switch to an HTTPS URL.
As you are attempting to connect to Github using SSH for the first time (no existing entry for Github in ~/.ssh/known_hosts yet), you are being asked to verify the key fingerprint of the remote host. Because, if an intruder host represents itself as a Github server, it's RSA fingerprint will be different from that of a GitHub server fingerprint.
You have two options.
You may just accept, considering you don't care about the authenticity of the remote host (Github in this case), or,
You may verify that you are actually getting connected to a Github server, by matching the RSA fingerprint you are presented to (in the prompt), with GitHub's SSH key fingerprints in base64 format.
The latter option is usually more preferable.
Just add Github fingerprint to known hosts this way:
mkdir -p ~/.ssh
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
Use one of the following two solutions:
1) Set up the SSH key
Follow the steps discussed on this GitHub help page.
https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh
2) Clone using git with HTTPS
Type (copy/paste) the following commands in a terminal on the machine where you would like to clone the repository
git config --global url."https://github.com/".insteadOf git#github.com:
git config --global url."https://".insteadOf git://
You can revert this change using the following commands
git config --global url."git#github.com:".insteadOf https://github.com/
git config --global url."git://".insteadOf https://
Try these steps:
Open Git Bash
Check for existing SSH keys:
$ ls -al ~/.ssh
If you already have them, you will see:
id_rsa.pub
id_ecdsa.pub
id_ed25519.pub
If you don't, generate one (Press Enter to accept the default file location):
$ ssh-keygen -t rsa -b 4096 -C "your_email#example.com"
To copy the key to clipboard:
$ clip < ~/.ssh/id_rsa.pub
Go to your account on Github/Settings/SSH and GPG keys/New SSH key
Paste your key there
Next, type:
$ git remote
If you see origin, remove it:
$ git remote remove origin
Continue with the last 2 steps provided on GitHub repo page...
$ git remote add origin git#github.com:USERNAME/REPONAME.git
$ git push -u origin master
Refresh your GitHub repo page
Voila!
1- Create SSH key
if you don't have the ssh-key create it like this:
ssh-keygen -t rsa -b 4096 -C "youremail#example.com"
2- Check your SSH key
For this go to your folder ssh, example:
cd ~/.ssh
after that, run this command line : ls
if you have the files: id_rsa, id_rsa.pub so the all is good
now you need to copy your id_rsa.pub ! (⚠️ NOT the id_rsa)
for this run cat id_rsa.pub and copy the result
3- Github / Gitlab
Go to your github / gitlab.
Follow the step by your hosting:
github: Click on your profile -> Settings -> SSH and GPG Keys -> New SSH key
gitlab: Click on your profile -> preferences -> SSH keys
past your id_rsa.pub that you have already copied !
4- If you have already did it and it's already not working ??
When your enter your ssh-key in github / gitlab your key have a Expiration date so you just need to change it
That it ! Have a good work 😀
You just need to type yes and it will work, for more information you can refer to the Official Github documentation. This will give an output saying
Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.

Gitkraken cannot use local SSH agent

I have recently changed my GitHub username and when I try to push with Authentication > Use local SSH agent selected, GitKraken push fails with following error:
Push Failed
Configured SSH key is invalid.
Please confirm that it is properly associated with your git provider.
Unselecting the option reveals proper private/public key pair located at
~/.ssh/id_rsa
~/.ssh/id_rsa.pub
and allows the push to be done.
I can also push from inside Eclipse, and via command line without error. The URL of the repository point to my new username.
So far I have checked several things:
ssh -T github.com
gives permission denied
Fingerprint of id_rsa.pub matches to a key existing in Github account.
The following command suggests that ssh tool tries rsa private key, but is rejected:
$ ssh -vT github.com
debug1: Offering RSA public key: /home/<user>/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/<user>/.ssh/id_dsa
debug1: Trying private key: /home/<user>/.ssh/id_ecdsa
debug1: Trying private key: /home/<user>/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
What is causing ssh -vT to fail in this case, and why doesn't it prevent git push/pull but fails when GitKraken tries pushing?
For me this was caused by an upgrade to OSX Sierra. I had to execute
ssh-add -k ~/.ssh/id_rsa
(you might have to replace that with the path of the key you are using). The command adds the ssh key to the git agent. For more information see the GitHub Help Page about adding SSH Keys.
You might have to add the command to some sort of setup file which is run at boot, because it seems like the ssh agent doesn't remember the key (at least for me).
For people who will come here in the future, my case was that pull/push working on vsc but gitkraken was giving me the message : no auth sock variable.
I went into file > preferences > SSH > unmarked use local SSH agent then it automatically found my id_rsa, ida_rsa.pub (you can browse and locate them manually if needed)
and now everything working fine.
OS: Arch,
gitkraken version: 7.7.2
What helped me resolve the issue was to go to GitKraken preferences and connect both Bitbucket and Github and authorize them.
After that tick the box in "general" that says use local ssh agent. (might be
If you have already set-up your local SSH agent, and your Git in terminal works, but Gitkraken does not, this might help:
First, start gitkraken from your terminal, instead of a desktop shortcut:
Open your favorite terminal
Run gitkraken
See if "Pull" works, or any other authenticated operation
It it works, you need to edit your Gitkraken desktop shortcut:
In my scenario, this is where my desktop shortcut is located, so: sudo vim /usr/share/applications/GitKraken.desktop
Change Exec=gitkraken %f to Exec=env SSH_AUTH_SOCK="${XDG_RUNTIME_DIR}/ssh-agent.socket" gitkraken %f

Add SSH key for both github and bitbucket in single PC

Is it possible to use both the github and bitbucket repo in personal computer.
if not, Let me know any other possibilities.
Thanks in advance.
Complete Guide to Add SSH keys for both github and bitbucket in single PC
if you already have one ssh key then you must have 2 files public(id_rsa.pub) and Private key(id_rsa) in the .ssh folder You can Skip the Step 2
Step 1. Prepare your default identity it Required for Both Account Before Doing Step 2 and Step 3
Determine your Git clone URL.
$ git remote -v
origin git#bitbucket.org:teamsinspace/bitbucketspacestation.git (fetch)
origin git#bitbucket.org:teamsinspace/bitbucketspacestation.git (push)
Update the remote URL with your Bitbucket username by replacing git#bitbucket.org with <username>#bitbucket.org.
For this step and the ones that follow, enter your username in place of .
$ git remote set-url origin <username>#bitbucket.org:teamsinspace/bitbucketspacestation.git
Step 2 : create the 1st ssh key with default names (id_rsa)
$ssh-keygen
You will see the following text:
Generating public/private RSA key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):
you can input the password to secure your file or you can press enter for all the steps and then it will create one ssh key.
By default, the system adds keys for all identities to the /Users/<username>/.ssh directory
You can check the already existing ssh key by following command
$ ls ~/.ssh
id_rsa id_rsa.pub
Two files should be there one with the name of the key(id_rsa) Private key second with the same (ir_rsa.pub) public key.
you can open make it visible by ctrl + h in Home Directory
then it will be shown
Second, Create your known hosts file if you not have already
To create your known hosts files-
touch known_hosts
STEP 3 : Sethup the Multiple account ssh
3.1 : Create 2nd Key With default name
You might be using one SSH key pair for working on your company's internal projects, now but you might be need a diffrent key for accessing a client's servers so you can create the key
By run the same command ssh-keygen again it will create the 2nd ssh key files with the name of [ id_rsa2 and id_rsa2.pub ]
3.2 : Create the 2nd Key with Custom Name
ssh-keygen -f NAME_OF_YOUR_KEY
$ ssh-keygen -f work_key it will create then 2 files
[ work_key, work_key.pub ]
if want to run the one key at a time then you can use this command before connecting to that repo for pull and push .
ssh-add -K ~/.ssh/YOUR_KEY_FILE
ssh-add -K ~/.ssh/work_key
Step 4 : Setup both two Accounts at the same time
You want to Setup both two Accounts at the same time then you will have to use the following command
Third Create your config file
To create your config file
touch config or open directly into any text editor,
Here is Example for One Github and one Bitbucket account
Host : name of your ssh setting you can give custom name
HostName : github domain or bitbucket domain
IdentityFile : path of your ssh file
#Work account
Host pers
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
UserKnownHostsFile ~/.ssh/known_hosts
IdentitiesOnly yes
#Personal account
Host work
HostName bitbucket.org
User git
IdentityFile ~/.ssh/work_key
UserKnownHostsFile ~/.ssh/known_hosts
IdentitiesOnly yes
Step 5 : Add your public keys to the Bitbucket or github account
For Bitbucket
For Github [Go to Setting of your Account -> SSH and GPG key]
Step 6 : Add your public permanently
ssh HOST(What we written in config file )
like
ssh work
if you got this error make sure you did Step 4 Correctly.
git#bitbucket.org: Permission denied (publickey).
or can be use this way as well
Now you can use
git clone `git#pers/project.git`
git clone `git#work/project.git`
Step 7 : auotmaticly pick by domain name we are requiesting to
Managing SSH keys can become cumbersome as soon as you need to use a second key. Traditionally, you would use ssh-add to store your keys to ssh-agent, typing in the password for each key. The problem is that you would need to do this every time you restart your computer, which can quickly become tedious.
if you have only two account and one in the github and one in the bitbucket you can use the following approch to auotmaticly pick by domain name we are requiesting to
#Work account
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
UserKnownHostsFile ~/.ssh/known_hosts
IdentitiesOnly yes
#Personal account
Host bitbucket.org
HostName bitbucket.org
User git
IdentityFile ~/.ssh/work_key
UserKnownHostsFile ~/.ssh/known_hosts
IdentitiesOnly yes
Here is a link to further guidance on it
https://www.freecodecamp.org/news/the-ultimate-guide-to-ssh-setting-up-ssh-keys/
https://support.atlassian.com/bitbucket-cloud/docs/set-up-additional-ssh-keys/
Yes it is. You tell git where the remote code lives from a per-repository configuration file. You can even push to GitHub and Bitbucket from the same repository if you want to.
See here for more details:
http://blog.lckymn.com/2013/03/11/git-push-to-pull-from-both-github-and-bitbucket/
One important piece will be connecting to each separately with SSH.
Your SSH keys should live in $HOME/.ssh and can contain any number of keys. The default name for an SSH key is id_rsa (or similar, depending on the protocol used to create it).
Try doing:
ls $HOME/.ssh
... to see what's in there.
I do what you are asking about myself and for me that brings up something like:
github-personal
github-personal.pub
bitbucket-work
bitbucket-work.pub
known_hosts
Where known_hosts is a file that contains a list of the servers I connect to and the public keys associated with them. The other files that end in .pub are my own public keys and the rest are my private keys.
You get your GitHub and Bitbucket keys into there by following their appropriate tutorials:
GitHub: https://help.github.com/articles/generating-ssh-keys/
Bitbucket: https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git
Yes, it is possible to use both the github and bitbucket repo in personal computer.
You can setup multiple SSH profiles.
First Generate your SSH keys To generate the first key-from your root folder
$ cd ~/.ssh
$ ssh-keygen -f work_key,
then enter a passphrase of your choice.
To generate the second key
$ ssh-keygen -f personal_key, then enter a passphrase of your choice.
Second, Create your known hosts file
To create your known hosts files-
touch known_hosts
Third Create your config file
To create your config file
touch config, then it would look something like this
#Work account
Host bitbucket.org
HostName bitbucket.org
User git
IdentityFile ~/.ssh/id_rsa
UserKnownHostsFile ~/.ssh/known_hosts
IdentitiesOnly yes
#Personal account
Host bitbucket.org
HostName bitbucket.org
User git
IdentityFile ~/.ssh/id_rsa2
UserKnownHostsFile ~/.ssh/known_hosts
IdentitiesOnly yes
Then add your SSH key to bitbucket. Go to bitbucket, settings, then SSH keys
pbcopy < id_rsa.pub (to copy the key) and paste it in bitbucket
Definitely YES. You can generate ssh key pair first, see How to generate, then go to .ssh directory, copy the content of id_rsa.pub, and paste into your github or bitbucket ssh setting area.
I make use of Sourcefree Desktop Application and My Gitbash prompt
to push my project to Bitbucket and Github repository simultaneously
below is what i did
right click to open bash shell of the folder you want to push
First you need to create key, i will advice make use of the same ssh key
create key
ssh-keygen -t rsa -C "your_email#example.com"
go to the folder directory
right click and click on git bash
then run the below command one after the other
git init
git add .
git commit -m "first"
open your sourcefree desktop app
click on + to open your local
repo file
create repo on bitbucket
then click repo icon
then click on repo icon to add
name: originbit
url: "repo link you created"
For your bitbucket you have to make use of both
public ssh key and private ssh key if you want to make use of
both public and private repository
To make use of ssh key earlier created
go to TOOLS icon of sourcefree App
Click on load tab
then resave it with .ppk extension
save the same key as private key and public key
in the same directory
dont input passhrase yet to avoid difficulties
just save it.
so that it can be loaded to pageant icon
to create new key
go to TOOLS icon of sourcefree
then click on create ssh key
change the bottom number to 2048
but if you are unable to change it
first create a new key then drag your mouse around the colum provided
in a zigzag way or any form once created.
change the 1048 to 2048 so that it can be accepted at bitbucket ssh
then recreate a new key
then save it as public key and private key
add key to the Pageant (check your desktop notification for this Pageant key icon)
add both private ssh key and ssh public key
Goto your bitbucket account seetings
and add the content of the two ssh keys
name them differently
go back to the bash shell
git status
git add -A
git pull originbit master
git commit -m "modified code"
git push originbit master
create repo on github
Open Sourcefree desktop app
copy the repo url
then click repo icon
then click on repo icon to add
then push on Sourcefree

Push to GitHub without a password using ssh-key

I generated an SSH key pair without a password and added the public key to GitHub.
Connection with
user#dev:/var/www/project# ssh -T git#github.com
Hi User! You've successfully authenticated, but GitHub does not provide shell access.
was successful and when I rename the key, it fails.
But when I want to push my changes, it stills ask me for my username and password combination.
Is there a way to push without a password?
If it is asking you for a username and password, your origin remote is pointing at the HTTPS URL rather than the SSH URL.
Change it to ssh.
For example, a GitHub project like Git will have an HTTPS URL:
https://github.com/<Username>/<Project>.git
And the SSH one:
git#github.com:<Username>/<Project>.git
You can do:
git remote set-url origin git#github.com:<Username>/<Project>.git
to change the URL.
In case you are indeed using the SSH URL, but still are asked for username and password when git pushing:
git remote set-url origin git#github.com:<Username>/<Project>.git
You should try troubleshooting with:
ssh -vT git#github.com
Below is a piece of sample output:
...
debug1: Trying private key: /c/Users/Yuci/.ssh/id_rsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_dsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
I actually have already added the public key to GitHub before, and I also have the private key locally. However, my private key is of a different name called /c/Users/Yuci/.ssh/github_rsa.
According to the sample output, Git is trying /c/Users/Yuci/.ssh/id_rsa, which I don't have. Therefore, I could simply copy github_rsa to id_rsa in the same directory.
cp /c/Users/Yuci/.ssh/github_rsa /c/Users/Yuci/.ssh/id_rsa
Now when I run ssh -vT git#github.com again, I have:
...
debug1: Trying private key: /c/Users/Yuci/.ssh/id_rsa
debug1: Authentication succeeded (publickey).
...
Hi <my username>! You've successfully authenticated, but GitHub does not provide shell access.
...
And now I can push to GitHub without being asked for username and password :-)
As usual, create an SSH key and paste the public key to GitHub. Add the private key to ssh-agent. (I assume this is what you have done.)
To check everything is correct, use ssh -T git#github.com
Next, don't forget to modify the remote point as follows:
git remote set-url origin git#github.com:username/your-repository.git
Additionally for gists, it seems you must leave out the username
git remote set-url origin git#gist.github.com:<Project code>
You have to use the SSH version, not HTTPS. When you clone from a repository, copy the link with the SSH version, because SSH is easy to use and solves all problems with access. You can set the access for every SSH you input into your account (like push, pull, clone, etc...)
Here is a link, which says why we need SSH and how to use it: step by step
Git Generate SSH Keys
for using SSH you must use $ git remote add origin git#github.com:USERNAME/REPOSITORY.git instead of git remote add origin remote_repository_URL.
you can check it with $ git remote -v, if you see 2 lines in the below format, it will work correctly:
origin git#github.com:username/repo-name.git (fetch)
origin git#github.com:username/repo-name.git (push)
Like the other users mentioned, you must convert it from using HTTPS to SSH. I don't see an answer with an end-to-end solution. After setting up the ssh keys, do (on your local machine) :
$ git remote set-url origin git#github.com:username/your_repo.git # Convert HTTPS -> SSH
$ ssh-add ~/.ssh/id_rsa_github # add private github ssh key ssh-agent (assuming you have it already running)
$ git push
You did everything ok but git still asking by password, this worked for me, execute the next commando in your current project's path:
~ ssh-add -K ~/.ssh/id_rsaYourIdRsa
Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsaYourIdRsa in the command with the name of your private key file.
Using the command line:
Enter ls -al ~/.ssh to see if existing SSH keys are present.
In the terminal is shows: No directory exist
Then generate a new SSH key
Step 1.
ssh-keygen -t rsa -b 4096 -C "your_email#example.com"
step 2.
Enter a file in which to save the key (/Users/you/.ssh/id_rsa): <here is file name and enter the key>
step 3.
Enter passphrase (empty for no passphrase): [Type a password]
Enter same passphrase again: [Type password again]