Using smartgit behind a proxy - windows

I'm working behind a company proxy (with credentials) for internet access and I'd like to reach a git repository hosted outside with smartgit for windows.
My repository is hosted mygit.be, my proxy is at 10.30.30.30 on port 8080 with user toto and mygit.be is accessible via ssh on port 25000 with user git and private key authentication.
After lot of searches on internet, I added a HOME environment variable pointing to c:\Users\toto\. I also copied my private key in c:\Users\toto\.ssh. And finally, I created a config file in c:\Users\toto\.ssh containing
Host mygit.be
ProxyCommand connect -H toto#10.30.30.30:8080 %h 25000
IdentityFile ~/.ssh/id_rsa_git
Now using
c:\Program Files\SmartGit\git\bin\git.exe ls-remote ssh://git#mygit.be:25000/~/myrepository.git refs/heads/*
is working fine. It's asking me the proxy password then gives me the result.
Enter proxy authentication password for toto#10.30.30.30:
b21e99487808231c992d50ca6bef483bea788708 refs/heads/dev
5021a3be4be18dbdb80f6ce2a01a7ca780862c30 refs/heads/master
My problem is now to have all that working within smartgit.
I configured it to use system ssh. But on the clone dialog, after the first 'Next' button, it hangs on Checking connection to repository without never asking me the proxy password.
So, what's the solution ?

So the solution is quite simple.
First solution
It is needed to add a SSH_ASKPASS environment variable containing
git gui--askpass
Now smartgit will ask for the proxy password.
The only remaining is problem is that smartgit will ask very often the password.
Second solution
Create a dos batch file passwd.bat containing
#echo mypassword
then back to solution one and the SSH_ASKPASS vairiable now contains
path-to-bat-file\passwd.bat

Related

Git configuration on windows for ssh access to Github

I have a Github account with multiple projects.
I have cloned these projects to my windows 10 computer using ssh key.
some time later, it appear my ssh keys were compromise so i delete my ssh on Github and locally, then regenerate new ones :
4096 bits
rsa2
saved the pub as ~/.ssh/git_id_rsa.pub
add the pub key to my Github ssh keys
saved the priv as ~/.ssh/git/git_id_rsa.ppk
converted to Openssh format as ~/.ssh/git_id_rsa
the fact is I want different ssh keys for my different web tools (one for GitHub, one for DigitalOcean, one for OVH cloud, etc...) and I want to specify witch key to use when connecting to each host. thats why I change the default name for the ssh generated with PuttyGen (and converted with the same).
I don't have passphrase on the git_id_rsa.ppk (nor git_id_rsa) keys, as it seems that GitHub dont like them (saw long time ago).
I've configure my (projecytdir)/.git/config like bellow :
[remote "origin"]
url = git#github.com:hdGuild/JenkinsServerOnDO.git
fetch = +refs/heads/*:refs/remotes/origin/*
identityfile= ~/.ssh/git_id_rsa
But when I try a Git Pull, I've got the following 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.
Following the following answers I've created the ~/.ssh/config file with the following (using OpenSSH key for GitHub), and it works :
Host github.com
IdentityFile ~/.ssh/git_id_rsa
The fact is that if I need the ~/.ssh/config file, why would I need to configure my local git with (projecytdir)/.git/config as I describe it above ?
I would like to configure my local git to use the right ssh key for Github, without having to explain it in my ~/.ssh/config file.
I'm sure it is (again) a configuration problem and I miss something somewhere, but I can't find where.
Please help :)
thank-you
Okay,
As previously, I answer my own question :D
After some more research, I found this post that explain how to specify in Git local config file, the ssh key to use for git sh connection.
The command is simply, in the above explained case, the following while in project directory :
git config core.sshCommand "ssh -i ~/.ssh/git_id_rsa -F /dev/null"
This way, the git_id-rsa will be used by git for ssh connections on this particular project (as it is a local configuration).
Thank-you for reading.

Can not pull over SSH

I have a Bitbucket repo from which I am able to pull and push over HTTPS.
Now, I'm trying to change HTTPS to SSH.
I have created an SSH key pair locally and I have added the public key to Bitbucket.
I have set the remote the following way:
git remote set-url origin git#my-repo.com:7999/my-project.git
Then, when I do git pull I am asking for my password three times and then I am denied permission:
Password:
Password:
Password:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,keyboard-interactive).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I have two questions:
1.Why am I asked for my password if I'm using SSH?(and I haven't setup a password when creating the SSH key)
2.Why can I not connect to the server?
You havn't added your private key to the ssh.agent.exe
You havn't told us about your environment.
This is how I use ssh keys daily.
Set alias for where my ssh-add is located. This just makes everything pretty.
Set-Alias ssh-add "C:\Program Files\Git\usr\bin\ssh-add.exe"
Start the SSH Agent - which servers your ssh keys
Start-SshAgent -Quiet
Add your private key to your session
ssh-add C:\Users\username\.ssh\privateKey
Thats all.
I run those three commands in my $profile for powershell on windows.
This URL is parsed as SSH over the standard port 22 with a path of 7999. Most likely the SSH server on port 22 does not authorize your git public key.
The syntax is
[user#]host.xz:path/to/repo.git/
Note that there's no room for a port.
The full SSH syntax is
ssh://[user#]host.xz[:port]/path/to/repo.git/
which should allow you to connect to the correct SSH port.
I often prefer to add an entry to my .ssh/config specifying the server details:
Host git
HostName git.example.net
User git
Port 7999
PasswordAuthentication no
Then I can use the short syntax of git:path/to/repo.git/.
Check the permission of your public key. Are you pulling it for first
time, then your key needs to have certain privileges.
You have locate your key file where you have save in your windows.
To set, view, change, or remove permissions on files and folders
Right-click the file or folder for which you want to set permissions, click Properties, and then click the Security tab.
Click Edit to open the Permissions for dialog box.
Do one of the following:
To set permissions for a group or user that does not appear in the Group or user names box, click Add. Type the name of the group or user you want to set permissions for, and then click OK.
To change or remove permissions from an existing group or user, click the name of the group or user.
Do one of the following:
- To allow or deny a permission, in the Permissions for box, select the Allow or Deny check box.
To remove the group or user from the Group or user names box, click Remove.
For more information you can check this link to setup the rights:
https://msdn.microsoft.com/en-us/library/bb727008.aspx

Multiple Bitbucket SSH accounts on same machine

I'm trying to get multiple Bitbucket accounts working from the same machine via SSH.
In my .ssh\config file, I have:
Host account1.bitbucket.org
Hostname bitbucket.org
PreferredAuthentications publickey
IdentitiesOnly yes
IdentityFile ~/.ssh/account1
Host account2.bitbucket.org
Hostname bitbucket.org
PreferredAuthentications publickey
IdentitiesOnly yes
IdentityFile ~/.ssh/account2
Then I'm changing the remote for the git repo to use the alias:
git#account1.bitbucket.org:myUserName/myRepoName.git
git#account2.bitbucket.org:myUserName/myRepoName.git
Then in Pageant (in the system tray), I'm adding both my PPK keys.
Unfortunately if I've added both keys to Pageant, only one of the accounts work.
If I only have one key in Pageant at a time, then it'll work for whichever Bitbucket account I added to Pageant.
So it looks like pageant isn't using the correct key if there's more than one key in its list.
Any ideas on why it's doing this?
This link on Atlassian Answers explains how to use PuTTY and SSH with multiple bitbucket account:
One way to resolve this is to perform the same configuration in PuTTY
too to disambiguate what key to send (and therefore which user to
authenticate as).
Start PuTTY (download it from putty.org if you don't have it)
Type 'bitbucket.org' in the host name field
Go to Connection > SSH > Auth in the tree
Specify the key to use for the BB user
Go back to 'Session' in the tree
Type an alias name underneath 'Saved Sessions' (e.g. bb-user1) and
Save
Repeat 2-6 for each BB user and save as a different session name
Then in your remote URLs, replace 'bitbucket.org' with the session
name (e.g. bb-user1) to disambiguate what SSH key to send first. This
is identical to using IdentityFile in OpenSSH.
Finally, you can add the keys in pageant to cache the key passcodes.
I got this working by not using Pageant. I'm using Sourcetree as a Git GUI, and in the options, there's a dropdown saying whether to use OpenSSH or Putty/Plink.
Based on the description by Steve Streeting here:
https://answers.atlassian.com/questions/164479/sourcetree-support-multiple-ssh-keys
It sounds like Pageant doesn't use the .ssh\config configuration anyway.
By changing to OpenSSH, then regenerating the keys using ssh-keygen, and adding the private keys via Sourcetree's "Tools .. Add SSH Keys" menu, this is now working perfectly using different keys across multiple accounts. I just need to alter the remote url of each git repo to use the correct alias in the config file (as described in my initial post).
Update:
I've written a blog post about this here:
http://www.danclarke.com/multiple-ssh-keys-for-git/

Unable to clone git repository from siteground

I'm trying to set up MS WebMatrix to use a Git repository from my siteground hosting account. I created the repository using their cpanel plugin and it tells me that I can clone it using this command
git clone ssh://username#sm3.siteground.biz:18765/home/username/public_html/
I replaced username of course and I created an rsa key using ssh-keygen. In the Webmatrix GUI it just opens a window saying "Clone is in progress" but it doesn't to anything.
And when I run that command in PowerShell, this is the output:
Cloning into 'public_html'...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Any help is highly appreciated!
EDIT:
I haven't used github before but I'm pretty sure I'm not connecting to it. The repository is on siteground's server I think. Anyway, I couldn't figure it out in PowerShell so now I'm using putty to load the appropriate key and connect using an external git tool (source tree) that doesn't use the same ssh client as PowerShell. That is the solution that's working for me now.
I'll leave this question open as maybe someone comes around and can help with how to set this up using PowerShell.
The missing piece to the Siteground guide is:
Create a blank file in ~/.ssh/ or C:\Users\username\.ssh on your computer. It does not matter what you name it. I named it siteground_dsa. You could also name it id_dsa_siteground.
Copy the private ssh key that you get from siteground.com and paste the whole of it in the this newly created file.
Open Git Bash locally on your computer and run the following command
$ eval ssh-agent -s
Then run the following. Remember to use the filename that you gave it.
$ ssh-add ~/.ssh/siteground_dsa
Now you need to enter the passphrase for the ssh key. You will have defined it when creating the ssh key.
Now you should be logged in and you can run git clone the directory of your wish.
git clone ssh://username#ams14.siteground.eu:18765/home/username/public_html/
To permanently add the SSH key extend ~/.ssh/config with the following and updating server_name and username.
Host server_name
User username
Port 18765
IdentityFile ~/.ssh/siteground_dsa
keep in mind that for Windows operators, you should write eval $(ssh-agent)
eval $(ssh-agent)
chmod 600 file_name
ssh-add C:\Users\username\.ssh\siteground
Then you can easily clone your file into your local server following inserting your passphrase of the SSH key.
GitHub isn't able to authenticate you. Probably your key isn't associated with your GitHub account.
Take a look to GitHub's recommended method

SourceTree on Windows: How to connect to SSH?

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

Resources