SourceTree Terminal prompting for password but repo authentication is done via SSH - atlassian-sourcetree

I'm running into an issue where whenver I try to open the terminal for a repository in Sourcetree and I perform a command e.g. git push, I am prompted for a password. The weird thing is that the repository authentication is done via ssh. The normal controls in the GUI work fine for pulling/pushing and doesn't prompt me for a password.
I have set up SSH configuration like so (which works fine for the regular Sourcetree GUI):
As per this thread with a similar issue: https://community.atlassian.com/t5/Sourcetree-questions/ssh-key-in-sourcetree-terminal/qaq-p/137178 I have copied the privkey.ppk to C:\Users\Niels\.ssh\.
Pageant shows the private key as being added too:
Why can I not perform Git operations on my repository from the terminal?

Git uses different format for keys than pagent and pagent is only usable for SourceTree not for Git system. You have to generate a new ssh key with ssh-keygen and you have to add that key to git server you want to use. Open a terminal (GitBash) and apply the following steps:
cd ~/.ssh
ssh-keygen -t rsa -C "your.email#example.com" -b 4096
cat id_rsa.pub | clip
Last command would copy the new public key to the clipboard. You can add it to Git server just bye pasting in the mentioned text box.

Related

Window 10 connection of Github , SSH issues

I am trying to connect git to GitHub. I am using window 10.
The SSH directory is not available.
$ cd .ssh
bash: cd: .ssh: No such file or directory
How can I connect the git to github?
Screenhot of git to github ssh connection problem
Windows 10 systems with build 1803 or newer and Windows Server 2019 come with an implementation of OpenSSH that's enabled by default. Some older versions may have this as an optional component that needs to be installed before it can be used.
Looks like in your case it may need to be installed (see if the folder "C:\Windows\System32\OpenSSH" exists and has files such as "ssh.exe" in it). If it is installed, then that directory needs to be added to the search path (type "echo %PATH%" in the command prompt window to see if it's in there).
Installation
Click on the "Settings" gear in the left pane of the Start Menu.
Click on "Apps".
Click on "Optional features".
Look in the list. If you do not see "OpenSSH Client", click "Add a feature".
"OpenSSH Client" and click "Install".
On analyzing deeper into the issue, it looks like you are searching or trying to cd to .ssh on the desktop which won't work.
Additionally, it looks like you are doing cat to a file that may not have existed as you have never generated public-private key pair(See ssh-keygen command for details)
Just try typing ssh and press enter to see that if it is actually the problem with ssh.
It should give output as(or similar to) :-
$ ssh
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]
[-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
[-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]
[-i identity_file] [-J [user#]host[:port]] [-L address]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-Q query_option] [-R address] [-S ctl_path] [-W host:port]
[-w local_tun[:remote_tun]] destination [command]
The .ssh directory is generally not available.
Not until you create it and use it with ssh-keygen (the one packaged with Git for Windows at C:\Program Files\Git\usr\bin\ssh-keygen.exe)
From a simple CMD:
cd %USERPROFILE%
mkdir .ssh
C:\Program Files\Git\usr\bin\ssh-keygen.exe -t rsa -P ""
You will get a:
%USERPROFILE%\.ssh\id_rsa (private key)
%USERPROFILE%\.ssh\id_rsa.pub (public key)
Copy the latter (the public key content) to your GitHub profile: that is how you associate Git to your GitHub account.
From there, you can open a Git bash session, and git clone using an SSH URL.
git clone git#github.com:me/myRepository

Start ssh-agent when windows boots along with ssh passphrase

I have a private Github repo, and I generated the SSH keys using windows.
I am trying to launch ssh-agent when my windows server starts, I can have the following command..
start "" "%PROGRAMFILES%\Git\bin\sh.exe" --login -i
but the problem with this is...I would need to enter the passphrase for my SSH key everytime i reboot.
I am working with a github repo, where whenever we commit a change then it triggers the GIT PULL on the server (using webhooks).
Anyway I can automate this?
You could make sure your .profile (called by sh --login -i) includes a call to ssh-agent with a file:
cat passfile | ssh-add -p keyfile
That way, every time the shell starts, the agent includes your key with its passphrase.

GIT push with SSH

I am having create difficulty finding reliable information on creating SSH keys in order to remove the need for username and password when doing git push and pull for a main repo and separate nested repos.
To make sure I have no existing errors deleted them from
https://github.com/settings/keys
And then followed this guide which in a nutshell advises:
Check for existing, I deleted all from here as well
ls -al ~/.ssh
then (accepting defaults with no passkey)
ssh-keygen -t rsa -b 4096 -C "your_email#example.com"
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
clip < ~/.ssh/id_rsa.pub
and pasting key at https://github.com/settings/keys
The guide seems to end here, however attempt to push the repo gives:
fatal: HttpRequestException encountered.
An error occurred while sending the request.
Username for 'https://github.com':
What steps have been missed here please.
Attempting to push via git bash

Auto push to github without username and password

after much messing around I have followed this tutorial on using a cmd prompt to push up to git hub
http://readwrite.com/2013/10/02/github-for-beginners-part-2
However I have had to do a few things differently. Generating and adding the public key in GitHub went fine, however, adding the private key on my local machine has been a real pain.
I finally added it by opening a cmd prompt as administrator. then going to the directory where github was installed I then rand the following cmds to install the private key
bash
eval $(ssh-agent)
cd to-directory-where-private-.ssh-file-was-located
ssh-add .ssh
Identity added: .ssh (.ssh)
Prior to that I had numerous errors. However, when I run this from a batch file
cd c:/LocalDevelopment/PhoneGap/PfpMetrol
git init
git status
git add PhonegapData.js
git commit -m "Add PhonegapData.js"
git remote -v
git push
pause
it is still asking me for a username and password.

Creating a passphrase for my ssh key on GitHub

I'm trying to setup a GitHub account and every time I get to the point of entering a passphrase for my SSH key my terminal freezes. Here are my steps:
Parkers-MacBook-Pro:~ ppreyer$ ssh-keygen -t rsa -C Parker.preyer1#gmail.com
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/ppreyer/.ssh/id_rsa): (/Users/ppreyer/.ssh/id_rsa):
Created directory '/Users/ppreyer/.ssh'.
Enter passphrase (empty for no passphrase): (WONT LET ME TYPE ANYTHING)
Anybody else run into this problem?
You're on a unix compliant machine. Therefore, most terminal-based password entry mechanisms use what's called a "Unix password field" (as far as I know, that's the most common name for it). You do not actually see the characters you are typing, but they are there. Simply make sure you type the same thing twice and you should be good.
Give it a try, type your password and press Enter. Type it again and press Enter again. You've just create an SSH passphrase.
I agree with MaxMackie's answer (upvoted), but I also like to generate my ssh keys non-interactively:
[space]ssh-keygen -t rsa -f "${H}/.ssh/myKey" -C "Gitolite Admin access (not interactive)" -q -P "xxxx"
That generates a 'mykey' private ssh key and a 'mykey.pub' public ssh key in my ~/.ssh directory.
Note the space before the command, in order to avoid, in my bash session, to record that command in the bash history (because I have defined a HISTCONTROL=ignorespace as in "Execute a terminal command without saving it to .bash_history on OS X?")