When I type git pull from command line, I can get the code without any problems.
When I open SourceTree for Windows, and try a Pull, I get:
git -c diff.mnemonicprefix=false -c core.quotepath=false fetch origin
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Completed with errors, see above.
What might I be doing wrong?
It seems like using SourceTree on windows you have to use Putty Agent. OpenSSH keys do not work.
If you have only OpenSSH key:
click Create or import SSH keys in Tools menu
in putty key generator select Import key from Conversions menu
select your private key and click on save private key
You now have PPK file containing your key.
In Source Tree Launch SSH Agent from tools menu and browse to your PPK file.
All operations should now work fine.
This works if you authenticate using a public/private key pair:
Open Sourcetree and go to "Tools > Create or Import SSH Keys" (this will open a PuTTY Key Generator window) and click on "Generate".
Once generated go to drupal.org and navigate to "My account > Profile > SSH Keys" and click "Add a public key".
Copy the generated public key from the "PuTTY Key Generator" window ("Public key for pasting into OpenSSH authorized_keys file:") to drupal.org and save it.
In the "PuTTY Key Generator" window enter a "Key passphrase" and "Confirm passphrase" and click "Save private key". Make sure to save it somwhere where you can find it again.
Close the "PuTTY Key Generator" window and in SourceTree go to "Tools > Launch SSH Agent (Pageant)". You should be able to select your private key file here. (the one you just saved)
Add your repository with the link provided by drupal.org. (username#git.drupal.org:project/your_project.git)
You don't need to use Putty in Windows but it is recommended, otherwise you'll have to re-add your ssh key every time you start SourceTree.
To do this go to 'Tools -> Add SSH Key...' and select the key that you provided in your cloud server (Git, BitBucket...). Now you'll be able to push/pull correctly provided you cloned your repository using the ssh url.
Keep in mind that this may apply to you only if you can successfully push/pull from the command line, if you don't then you have some other kind of problem.
If you accidentally cloned your repository using the https url then:
git remote set-url <remote> <ssh-uri>
Like:
git remote set-url origin git#github.com...
Related
I've problems using GIT with the shell, Visual Studio Code and Visual Studio 2015 (community edition).
Earlier this year I started using GIT with eGit (under Eclipse of course) without any problems. I installed GIT on my server, created a ssh key pair and after a few tests it worked (and still works).
However, now I want to use that GIT on my server with Visual Studio Code and maybe later with Visual Studio 2015.
I got stuck on this issue: GIT trys to use my PPK and asks me for the passphrase (which is emtpy). If I enter a wrong phrase it asks again and continues only if I answer correct (simply enter key). So I think everything is OK till here. But then it asks for the user password for the git-user (the right one btw) on the server and fails. Why?
In the log of my server I can't see any entry about logging in using the key file, only the errors about trying to log in with the password (which is disabled).
If I use putty with that key file I'm able to connect to my GIT server and I also get an entry in the log file. So I'm sure that everything is OK with the server.
What am I missing? I would appreciate any help about that!
Using it with Visual Studio 2015 (I can't solve the issue that it doesn't find libssh when I try to recompile the GIT module following the well known blog entry from Bernardo Pastorelli) or saving the enter key press would be a bonus, however, I would be happy if I could use GIT with key file under Shell / Visual Studio Code at all.
OS: Windows 7 64 bit
GIT 2.10.2.windows.1
VSC: V 1.7.2
TIA!
I'll try to answer the simpler question in your Post:
I would be happy if I could use GIT with key file under Shell
Once, that is done, you can build on it.
Git for windows uses Openssh and therefore will not be able to use the putty PPK file directly.
Two ways forward
Option 1: Convert PPK file to OpenSSH format
Steps to do so:
Open your private key in PuTTYGen
Top menu “Conversions”->”Export OpenSSH key”.
Save the new OpenSSH key when prompted.
To use this new openssh key for your git server, do the following:
Open up Git Bash shell and there edit ~/.ssh/config (create ~/.ssh/ if it does not exist) and define this host:
Host AuxBurgerGitServer
Hostname whatevers-your-git-remote-is
User the-git-user
IdentityFile ~/.ssh/the-open-ssh-key-exported-before
Test this by doing a ssh -T AuxBurgerGitServer which should not show any errors.
If you go this way, you should use the HOST defined above whenever referring to any repositories on this host. Therefore, for example, to clone a repo you would do something like:
git clone ssh://AuxBurgerGitServer/some-repo-name
Option 2: Configure your GIT to use pageant
You can load your PPK file in pageant and configure GIT to use pageant for authentication.
For this, the only thing you would need is to setup an environment variable like so using:
Control Panel → System → Advanced system settings → Environment variables
(or on Windows 10: Control Panel → Search → Environment variables)
GIT_SSH=c:\Program Files\Putty\plink.exe
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 cannot find a simple step-by-step guide to setup an OSX machine with Bitbucket and SSH.
So it requires me to google for different pages (to create SSH keys and to set them up in Bitbucket) whenever I'm setting up a new machine. It seems valuable to have one complete list available in StackOverflow.
It's actually pretty straightforward.
Check if you have a public key already that you could reuse:
ls -a ~/.ssh
If there is NO public key file id_rsa.pub then generate one:
ssh-keygen
Accept defaults. I don't enter password because I prefer to keep my hard drive encrypted whenever the repository contents are critical.
Copy your public key to clipboard:
pbcopy < ~/.ssh/id_rsa.pub
Let Bitbucket know the identity of your computer:
Go to https://bitbucket.org
Open your account settings under your avatar
Find "SSH keys" and choose to add a new one
Paste your public key from pbcopy
Clone (pull, push or whatever) your repository using SSH:
hg clone ssh://hg#bitbucket.org/<username>/<repository>
First time you will get a warning similar to this:
The authenticity of host 'bitbucket.org (104.192.143.1)' can't be established.
RSA key fingerprint is 97:...:40.
You should google for "Bitbucket fingerprint" and compare what you see in terminal with what Atlassian documentation gives because fingerprints could change and can be faked.
Have fun!
I have an SSH access to my web hosting, it works great with PuTTY (I just had to enter my domain, username and password), however it seems much more complicated with SourceTree.
While PuTTY has a field for "Host Name", "username" and "password", SourceTree doesn't and requires a special file ".ppk"?!
I need to connect SourceTree to my web hosting via SSH for the obvious reason that I want to use it to push to a remote repository located on my web hosting.
So how do I get a .ppk file generated from my domain/username/password? Any help greatly appreciated!
PS: I've noticed that they made it exceptionally easy to connect to BitBucket by offering two simple fields: "username" and "password", and made it exceptionally difficult to connect to a third-party SSH... Is it an intentional attempt to prevent competition?!
I had to do some additional work from Patoshi's answer.
In Tools > Options > General > SSH Client Configuration, I had to point it to the id_rsa key, and select OpenSSH as the SSH Client (Putty/PLink is selected by default).
Then each time you start SourceTree, a prompt will appear asking for the passphrase to decrypt the id_rsa key (assuming you created it with a passphrase to encrypt it). This looks like so:
At that point, I could go to the Clone page, paste in the SSH address from my Gitlab project (git#localgit.local:Blah/Whatever.git) and it cloned it. No extra prompts for username or password (since it is using SSH keys).
There are two ways to connect SourceTree to any SSH.
1: The Simplest Way
The simplest way is by using your domain name, username and password provided by your Web Hosting Provider:
Simply use the following syntax: ssh://username#example.com/ – SourceTree will then prompt you to enter your password whenever you push to that SSH:
If you check the Remember password checkbox, your password will be saved and you will not be prompted again for it. You can edit or remove the stored password at a later time by going to Tools > Options > Authentication as shown on the image below:
Note: In my case (1&1 Shared Hosting), the username and password were both the same as my main FTP account.
2: The More Complex Way
The more complex way is by using a Private/Public Keys Pair:
This implies generating two keys (one "private" and one "public") using the "PuTTY Key Generator" (in SourceTree go to Tools > Create or Import SSH Keys).
Once generated, save the private key to a .ppk file and load it in SourceTree (Tools > Create or Import SSH Keys > Load). It's not over yet: now you must add the public key to your server. To do that, add it to the following file on your web server: /.ssh/authorized_keys.
If this file doesn't exist, save your public key to a file named authorized_keys and upload it to your server via FTP. You must upload it into a directory named /.ssh/ located at the root (if it doesn't exist, simply create it).
Note: Make sure to use the main FTP account of your hosting account. If it doesn't work, adjust the permissions (chmod) of the authorized_keys file and set it to 777 using your FTP software (Right-click on "authorized_keys" > File permissions):
No need for command line whatsoever.
I had some trouble getting SourceTree working with an existing git repo that resided on gitlab. I also had to figure out why it wasn't connecting as I was using puttygen to generate the keys.
Make sure after you generate your keys to export it to the OpenSSH format
You place this file in your c:\user\MYUSERNAME.ssh folder as the file:
id_rsa
id_rsa.pub
the id_rsa is the private key file and .pub is the public key file that you paste into your other application, which in my case was gitlab.
Generate SSH key, private and public
Source Tree > Tools > Create or Import SSH Keys
Putty
Click Generate
Save public key under .ssh folder
Save private key under .ssh folder
Add private key to Pageant, running in background
Clone the git project using SSH key
I have created an ssh key pair using putty within Source Tree on Windows, and then added that to my repo client (I use Gitlab on a personal server).
This works fine from gitbash (cloning and pushing etc) and via SourceTree for OSX but after adding the .ppk key to pageant, which is actively running and seems to have loaded the key correctly, I cannot seem to clone via SourceTree. I get a "This is not a valid source Path/URL" when adding the repo path with details stating:
fatal: Could not read from remote repository. Please make sure you
have the correct access rights and repository exists.
If I add an existing repo that I have cloned using the same ssh key pair via git bash (by just drag dropping the folder into Source Tree for Windows) that seems to work up to a point - I can commit and see history etc. When I try to Push, however, it fails with much the same message (I've altered the repo path):
git -c diff.mnemonicprefix=false -c core.quotepath=false push -v
--tags origin master:master Pushing to git#MyServer.com:MyRepo.git
fatal: Could not read from remote repository. Please make sure you
have the correct access rights and the repository exists.
Completed with errors, see above.
As far as I can tell Pageant is up and running with the correct (well only) ssh key on my machine.
Any help is very welcomed.
Ok so this is a little embarrasing/confusing.
It would seem that I did not copy the correct public key onto my repo management web interface. The thing is, I copied the public key from git bash using the command:
clip < ~/.ssh/id_rsa.pub
But that seems to give me a different public key from what I actually get opening id_rsa.pub in a text editor...
Is that normal? Why is it different? Why does it work within gitbash and not in SourceTree (via pageant).
Anyway, copying the contents of my public key in directly from the file when opened in notepad got things to work with SourceTree and Pageant etc.