I\'ve been somewhat \'putting up\' with Github always asking for my username and password when I clone a repository. I want to bypass this step because it is an annoyance w
I had to execute:
eval `ssh-agent -s`
ssh-add
Note: You will have to do this again after every restart. If you want to avoid it, then enter it in your ".bashrc" file which is in C:\Users\<<USERNAME>>\.bashrc on windows. It is probably hidden, so make sure that you can see hidden files.
Solution found here.
Use ssh-add command to add your public key to the ssh-agent.
ssh-add
Make sure the ssh public key e.g. ~/.ssh/id_rsa.pub is what you have in your repo settings.
Make sure you can actually ssh into the server e.g. For Bitbucket:
ssh -T git@bitbucket.org
Update the url to move from https to ssh. You can check which you use by checking the output of:
git remote -v
If you see a https:// in the urls, then you are still using https. To update it: Take the url and just replace https:// with ssh:// e.g. Change:
https://git@bitbucket.org/../..
To:
ssh://git@bitbucket.org/../..
Referenced: https://docs.github.com/en/github/using-git/changing-a-remotes-url#switching-remote-urls-from-https-to-ssh
This is what worked for me:
git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"
Generally, here are the steps to allow you make a remote connection to your server using ssh without password:
Create a pair of rsa private and public key
$ ssh-keygen -t rsa -b 4096 -C "your comments"
Copy your public key and login to your remote server
Add your public key to .ssh/authorized_keys
If you have multiple ssh keys in your computer you might to add your key using ssh-add
$ ssh-add /path/to/private/key
Then try ssh to your server
$ ssh username@your_ip_address
Source: http://diary-of-programmer.blogspot.com/2018/08/tips-how-to-ssh-to-your-digitalocean.html
SSH Key - Still asking for password and passphrase
If on Windows and using PuTTY as the SSH key generator, this quick & easy solution turned out to be the only working solution for me using a plain windows command line:
pageant.exe and plink.exe.ppk extension"full\path\to\your\pageant.exe" "full\path\to\your\key.ppk" (must be quoted). This will execute the pageant service and register your key (after entering the password).GIT_SSH=full\path\to\plink.exe (must not be quoted). This will redirect git ssh-communication-related commands to plink that will use the pageantservice for authentication without asking for the password again.Done!
Note1: This documentation warns about some peculiarities when working with the GIT_SHH environment variable settings. I can push, pull, fetch with any number of additional parameters to the command and everything works just fine for me (without any need to write an extra script as suggested therein).
Note2: Path to PuTTY instalation is usually in PATH so may be omitted. Anyway, I prefer specifying the full paths.
Automation:
The following batch file can be run before using git from command line. It illustrates the usage of the settings:
git-init.bat
@ECHO OFF
:: Use start since the call is blocking
START "%ProgramFiles%\PuTTY\pageant.exe" "%HOMEDRIVE%%HOMEPATH%\.ssh\id_ed00000.ppk"
SET GIT_SSH=%ProgramFiles%\PuTTY\plink.exe
Anyway, I have the GIT_SSH variable set in SystemPropertiesAdvanced.exe > Environment variables and the pageant.exe added as the Run registry key (*).
(*) Steps to add a Run registry key>
regedit.exeHKEY_CURRENT_USER > Software > Microsoft > Windows > CurrentVersion > RunEdit > New > String ValueEdit > Modify... (or double-click)pageant.exe and public key, e.g., "C:\Program Files\PuTTY\pageant.exe" "C:\Users\username\.ssh\id_ed00000.ppk" (notice that %ProgramFiles% etc. variables do not work in here unless choosing Expandable string value in place of the String value in step 3.).There may be times in which you don't want the passphrase stored in the keychain, but don't want to have to enter the passphrase over and over again.
You can do that like this:
ssh-add ~/.ssh/id_rsa
This will ask you for the passphrase, enter it and it will not ask again until you restart.
As @dennis points out in the comments, to persist the passphrase through restarts by storing it in your keychain, you can use the -K option (-k for Ubuntu) when adding the identity like this:
ssh-add -K ~/.ssh/id_rsa
Once again, this will ask you for the passphrase, enter it and this time it will never ask again for this identity.