I have generated a pair of keys on my windows local machine.
I have a folder c:/users/me/.ssh containing :
the private key
the public key
the known_hosts file
I have uploaded the public key to my github profile.
When I open a powershell terminal and run any git command to interact with my repository, like :
git fetch my_repo_name
everything is working well.
The problem is that, I do not want to use the default private key located in the default .ssh folder, and I want to be able to specify my private key, but when I run the following command :
ssh-agent $(ssh-add C:/Users/Me/Pictures/id_rsa; git fetch my_repo_name)
I get the following error :
Identity added: C:/Users/Me/Pictures/id_rsa (C:/Users/Me/Pictures/id_rsa)
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
ps : the pictures folder is just used for the example, the point is that I want to be able to use a specific located private ssh key other than the default one.
Related
I'm trying to configure git so I don't have to keep authenticating (and also learn a bit more about git).
I had previously been using password-based authentication, which is repetitive to keep typing in my passwords. I followed the steps (using windows) to set up SSH keys in github. I gave my key a specific name, anticipating that I will need more than one SSH key at some point. It doesn't make sense to always have id_rsa for github! I received the email that the key was successfully created, and I used git bash (because windows) to start the SSH client silently and added my private key. But running a git clone gave me this error:
git#github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I then had the idea to try it with the default name (id_rsa), rather than my custom name, and of course it works. So my question is how do I avoid this? I don't want the default name to be reserved for github.
You can set up an ssh configuration file to tell the ssh command to use that specific key when connecting to github.
Create the file .ssh/config with the content:
Host github.com
IdentityFile ~/.ssh/github_rsa_key
Assuming that you've named your private key ~/.ssh/github_rsa_key.
Now try connecting to github:
$ ssh git#github.com
You should see:
Hi <your github username>! You've successfully authenticated, but GitHub does not provide shell access.
First, I am an absolute noob with git, repos and command line. I have repo on Bitbucket and I basically want to be able to push to the repository via gitbash without entering a password each time.
What I have:
A repository on Bitbucket with the code already set up.
A local directory where the repository is cloned.
A public key and a private key generated via PuTTY.
Public key added to Bitbucket via the Manage SSH keys page.
How do I now make it work so that I don't have to enter the password each time I push from the gitbash terminal? I'm using Windows 10.
Please follow the steps to add ssh key into bitbucket account to solve your issue.
Open git bash terminal and enter the command ssh-keygen -t rsa -C "your email address"
Enter passphrase (leave it blank) and enter
Enter the same phrase again (leave it blank) and enter
Copy the id_rsa.pub file content from where it is residing in your system (C:\Users\username\.ssh)
Login to bitbucket account and click top right most user icon ->bitbucket settings->ssh keys under security menu then paste into key field and save it.
6.Restart your git bash terminal and enter git init command and add ssh git repository location git#bitbucket.org:username/repository_name.git which is present in your bitbucket repository.
Enjoy!
There are two ways to load a remote git repository: using SSH and using HTTPS.
SSH will use a key pair, and requires the public key to be added to your BitBucket/GitHub profile.
HTTPS requires your BitBucket/GitHub username and password. You will be promoted for your password every time you interact with the remote server (clone, fetch, push, pull).
If you are currently being prompted for a password, that means the remote URL is currently set to use HTTPS. You can determine this be running git remote -v. To change to use SSH, you need to update the remote URL to the SSH URL by running git remote set-url <remote alias> <SSH URL>. If you only have one remote server, <remote alias> will be origin. You can find the SSH URL in BitBucket/GitHub under the clone option of the repository.
1) create .ssh folder under your home directory like:
mkdir C:\Users\USERNAME\.ssh
2) Copy id_rsa and id_rsa.pub into directory from previous step
3) Close and open cmd (console window)
4) You need to clone the repository as SSH repository, like:
git clone ssh://git#bitbucket.test.com:USERNAME/repository.git
Then it should work.
Following this guide
I think you are missing that after you have generated the SSH keypair, you need to add the SSH private key to pageant, PuTTY’s key management tool.
First, run pageant, which can be found in the directory where you have installed PuTTY package (remember, by default: c:\Program Files\PuTTY). You will see a small icon in your system tray (see the screenshot to the right), which indicates pageant is started. Click on the icon and in pageant window click “Add Keys”. Add the private key that was generated by puttygen in the previous step. The private key has extension .ppk, that is the easiest way to distinguish it from the public key you have created.
After you add the SSH key, you should see it in pageant key list.
Don't use PuTTY to generate the key.
Create a new key with ssh-keygen in .ssh. Leave passwords blank.
Open that new key in PuTTY.
Copy and paste it into the Bitbucket Key field.
Save key with PuTTY and Bitbucket.
It should work.
if you need to update multiple putty sessions on windows via powershell:
set-Itemproperty -path HKCU:\Software\SimonTatham\PuTTY\Sessions\sessionname -name PublicKeyFile -value "C:\Users\username.ssh\putty.ppk"
For Windows 7 users:
Open Git Bash and type ssh-keygen, and press Enter three times
(one for location, and two for empty passphrase).
Now, a dir .ssh should list these two files: id_rsa id_rsa.pub
Add the public key to your Bitbucket settings, as described in Set
up an SSH key
,
Step 3. You basically copy paste the contents of file "id_rsa.pub"
to your profile in BitBucket via the web interface (no admin rights
required of course).
Restart Git Bash.
Go the destination directory, where you would like to clone your repository
and do a git init
Get the ssh from the Clone of the repo, and then do git clone ssh://git#bitbucket.test.com:YOURUSERNAME/myrepository.git
I am unable to clone any repositories from github. I always get this error message
fatal: Could not read from remote repository. Please make sure you have the
correct access rights and the repository exists
I have taken care of the following :
Set my path variable to ;C:\Program Files (x86)\Git\cmd; and C:\Program Files (x86)\Git\bin;
I have generated the public key and linked id_rsa.pub with git
I have seen all the related links and am unable to resolve this issue.
If you have issue with the ssh key, you can at least use as a workaround https url:
git clone https://github.com/username/reponame
Regarding ssh, make sure that:
environment variable HOME is defines, and that your private/public ssh keys are in:
%HOME%\.ssh\id_rsa
%HOME%\.ssh\id_rsa.pub
your public ssh key is added to your GitHub account.
my client sent me two keygen files (one is public and the other is private) and asked me to follow these steps to get their source:
$ vim .ssh/config # create a ssh config
Host git.xxx.com
IdentityFile ~/.ssh/keys/yourSource
$ keychain ~/.ssh/keys/yourSource # load the private key with keychain
$ git clone git#git.yourSource.com:something.git
$ cd something
I've put the keygen files they sent me in ~/.ssh/keys. I gave them my public key and they said they'd set it up.
But I have problems after creating the config file. I wasn't allowed to use "keychain" command on windows platform. (Git bash displays "command not found".) Is there any way else I can load the private key?
I doubt you need the keychain command. This one is used on Unix environments (Linux/Mac) only.
What you need on Windows is this setup:
in your c:\Users\.ssh folder, have two key files (default names id_rsa and id_rsa.pub). Use those provided or generate some with ssh-keygen
provide the contents of the public key to your client for setup with git repository
test the setup with git clone.
It is a bit strange that the client has provided you with both private and public keys rather than asking you to generate your own. The whole purpose of the public/private keys in security is to ensure that the private remains private so that the identity of one user/commiter can't be duplicated. If they have your private key then someone might (even accidentally) use your identity to access the git repository.
I'm able to authenticate, generate, push etc just fine with my SSH keys and Moovweb credentials on my Mac and Linux machines.
However, on my Windows machine, using Git Bash, I get an SSH Permission denied (publickey) error. The error message is below:
$> moov generate 123dsfsdsf nytimes.com
Running environment checks.
Verifying that git is installed...OK
Checking that current 123dsfsdsf directory doesn't exist...OK
Registering project with MoovCloud.
Authenticating with MoovCloud.
Checking for git access...Enter passphrase for key '/Users/firstname.lastname/.ssh/id_rsa':
Enter passphrase for key '/Users/firstname.lastname/.ssh/id_rsa':
FAILED
> Need to upload an ssh key in order to generate a project...
Found the following SSH public keys:
1 ) id_rsa.pub
2 ) new_rsa.pub
Which would you like to use with your Moovweb account? 2
Uploading public key...
Successfully uploaded public key new_rsa.pub as 'firstname.lastname#GGT.local'
You are now ready to push projects to MoovCloud!
Creating project in MoovCloud...OK
Generating files...OK
Cloning project locally.
Enter passphrase for key '/Users/firstname.lastname/.ssh/id_rsa':
Enter passphrase for key '/Users/firstname.lastname/.ssh/id_rsa':
Cloning into '123dsfsdsf'...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
ERROR: Error cloning git repo: exit status 128
Please try cloning the repository (git clone moov#git.moovweb.com:firstnameglastname/123dsfsdsf.git) again later.
Try 'moov help generate' to find out details.
Seems like a Windows-specific SSH error. Any workarounds?
So as mentioned in prior answers, the Permission denied error in Windows is because you are trying to use a key other than id_rsa.
Windows lacks the bells and whistles that Linux and Mac have to try out all your public keys when trying to connect to a server via SSH. If you're using the ssh command, you can tell it which key to use by passing the -i flag followed by the path to the key to use:
ssh -i ~/.ssh/moovweb_rsa moov#git.moovweb.com
The above command should work just fine if you've uploaded moovweb_rsa.pub to the console (either via the moov login command or the console UI). However, trying any git related commands should fail because Git doesn't give you the ability to chose which key to use when connecting to the git remote. Because of this, SSH is forced to use the default key, id_rsa, and if that key doesn't work (or doesn't exist), then the connection fails with a permission denied error.
One possible solution, as suggested in other answers, is to simply rename your key to id_rsa. For most people, this is a fine solution. However, if you already have an id_rsa key and you would prefer to use a different key with Moovweb, you can edit your ~/.ssh/config file by adding the following contents:
Host git.moovweb.com
IdentityFile ~/.ssh/moovweb_rsa
If you append the above lines to your ~/.ssh/config file (create it if it doesn't exist), you should be able to successfully get Git to communicate with the Moovweb remote git server. The config basically tells SSH that for the given host (git.moovweb.com), SSH should use the given key rather than the default.
It's worth nothing that this happens to all Git remotes; interactions with Github, Heroku, etc... also suffer through this problem in Windows. You could easily extend your ~/.ssh/config file to use separate SSH keys for each one of those services if you so desired:
Host git.moovweb.com
IdentityFile ~/.ssh/moovweb_rsa
Host github.com
IdentityFile ~/.ssh/github_rsa
Host heroku.com
IdentityFile ~/.ssh/heroku_rsa
Quick & dirty solution: use only the default id_rsa.pub key
Some notes:
make sure you enter the right passphrase to id_rsa.pub
do not use your other key, new_rsa.pub
It turns out that Windows Git Bash doesn't quite come with all the cool utilities Mac/Linux users are used to. Specifically, you don't have ssh-agent running to help handle multiple keys. Without ssh-agent, the git command only seems to use the default id_rsa.pub key.
You can verify this is an SSH/Windows issue following Github's awesome SSH troubleshooting guide. You'll get a Permission denied (publickey) no matter which SSH/Git server you try to connect to.