Using SSH Keys on different Mac - macos

I have GIT and my repos setup on a MacBook Air. I'm trying to clone the repo on my iMac. My understanding was that I needed to copy my key over from the /.ssh folder on the MBA to the same folder iMac.
However, when I try and clone the repo on the iMac, I get the following error:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I've done a little research already and have verified that...
I have the latest version of GIT and that my user.name and user.email variables are configured correctly. (New Mac - new SSH keys for github?)
the ownership & permissions on the .gitconfig file and parent folder are r/w and owned by my user. (Trouble setting up Tower with my GitHub Account - error: could not lock config file)
my $HOME environment variable points to my users working directory. (Trouble setting up git with my GitHub Account error: could not lock config file)
At this point, I am all out of ideas and could really use some advice.
Suggestions?
Thanks!

Can't believe I found the solution right after I got done posting this, but for those who are copying keys to new machines, you have to let SSH know the keys are there. See this answer for details:
https://stackoverflow.com/a/12100237/337824

Related

Git prompting for password when using SSH, even when SSH keys are present (but running as admin works). What is the issue?

In a corporate environment running Windows I have the following issue:
Using git via SSH via
git clone git#server:repo.git
I am prompted for a password:
git clone git#server:repo.git
Cloning into 'repo'...
git#server's password:
The SSH Key is not found, although my SSH key resides in C:\Users\[USERNAME]\.ssh.
However, running the command shell (CMD) as administrator, everything works just fine.
What is the issue and how can it be fixed?
(Note: I am answering my own question since the issue wasted hours of my time and I did not see it in other issues having similar "access denied" symptoms).
Getting "access denied" or haven SSH keys not recognised may have a variety of reasons, see also
https://serverfault.com/questions/194567/how-do-i-tell-git-for-windows-where-to-find-my-private-rsa-key
The issue above - where git works when run as local admin, but not as user - is possibly related to a specific setup in a corporate environment. In my case the machine had a folder C:\Users\[USERNAME] but also a profile on a network mounted drive (say N). The .ssh folder with my key resided in C:\Users\[USERNAME] but git was looking in N:
Running as (Local) Administrator on the Machine changed the behaviour and used the profile from C:\Users\[USERNAME].
To find your home folder:
open Git Bash on Windows
type cd ~;pwd
The issue is ultimately related to different settings of the environment variables HOMEDRIVE, HOMESHARE or USERPROFILE, see also Git bash home directory different from Git extension than Git Bash

ssh and GIT: couldn't resolve hostname

Using Win7, Gitolite, and TortoiseGIT
today I updated my GIT to version 2.6.1, therefore I had to deinstall the old version.
Long time ago I created a ssh-config file to have easier access to my repositories and all was working fine since today.
After the update I tried to clone an existing repository and got following error:
ssh: couldn't resolve hostname gitbox: Name or service not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
Seems to me like GIT doesn't know where the ssh-config file is located.
Following helped but I'm not very happy with that solution:
Starting GIT GUI
Trying to clone a repository -> Same error as before
figured out that GIT created a new folder at /c/Users/newUser/
Inside the folder I found .gitconfig
Create .ssh folder here
Copy rsa key and config file here
All working as before
Can someone explain what happened here? Or how can I tell GIT/ssh where my config file was initially located?
Thank you very much!
Can someone explain what happened here?
You need to make sure that HOME is properly set to %USERPROFILE%: by default, git will look for the global config and for .ssh settings in %HOME%.
By default, calling c:\path\to\PortableGit-2.6.1-64-bit\git-cmd.exe would initiate a CMD session with HOME correctly set.
c:\path\to\PortableGit-2.6.1-64-bit\git-bash.exe would do the same for $HOME, in a bash session.

Is stash only meant for sourcetree as its not able to do it from command line in windows?

Is Stash only meant for Sourcetree, as it's not able to do it from console in windows? I have cloned the project from stash.
But I'm unable to push or pull from command prompt, whereas I can do it from Sourcetree to that particular project folder.
Error:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
So is it separately treated or am I doing anything wrong in SSH key setup? Is it a mistake of source tree or Windows machine?
Last question:
How can I add multiple ssh keys for different account to it because default directory is: C:\Users\%user%\.ssh
Stash works with any git client. It looks like your command line client is not using the same SSH key as you're using from SourceTree

Git pushes files to github with wrong username

I'm trying to push my committed changes to Github using Terminal on Mac OS but
it keeps saying that the access to the repository is denied to my old github user
Permission to myuser/test1.git denied to "OldUser".
fatal: unable to access 'https://github.com/"NewUser"/test1.git/': The requested URL returned error: 403
I found some similar problems but none of the answers worked for me:
First of all Iv'e removed all the SSH keys from my mac and created a new one which I then synced with my github account.
Second, I have set the Global config for git to my new username and email using
git config --global user.name AND user.email
When I changed the user and email in the git local config file in my project dir (thinking at least that would work), I was surprised to see the same error when pushing, with my old user name popping out again.. (I really thought a local config would override any old global values) I just don't know where to look anymore..
There are no git environment variables defined and the SSH keys were all re-created.
seems that the last option is to re-install git which would be a really ugly way out..
Oh! BTW when i'm trying to push to github using the dedicated MacOS app it works just fine! I wasn't surprised a bit because all users reporting this problem said that the app worked for them just fine.. Just thought I mention it!
So, if anyone got an answer (or at least a hunch) it would help me a lot.
BTW when I'm trying to push to github using the dedicated MacOS app it works just fine!
It is possible the gitHub for Mac is using https url, with your GitHub login/password (which GitHub for Mac is caching).
Check the url associated with your remote origin:
git remote -v
If it is an https url (like your error message suggests "unable to access 'https://github.com/"NewUser"/test1.git/'"), no amount of SSH fiddling will change that error.
Maybe, for http url, the Credential Caching on Mac OS X has still the old credentials.
I had the exact same error on Windows and apparently it's a Git problem. Thanks to ayan4m1 at github forums (https://github.com/Microsoft/Git-Credential-Manager-for-Windows/issues/152) I finally fixed this issue in Windows using notepad in admin mode to delete the credential.helper = manager lines from the C:\Program Files\Git\mingw64\etc.gitconfig file. Nothing else worked.
Apparently since I was in non-elevated mode in Git bash from my IDE none of my global commands were able to overwrite the global file. Hope this helps and saves time for someone else with this issue.

git push heroku master Permission denied (publickey)

Edit #3
Updating this at the top because it solved my issue and gave me a good troubleshooting step I didn't know about (and could save you some time, too)
Try getting the output of ssh -vvv git#heroku.com. For me, ssh was getting hung up on trying keys in /c/Program Files (x86)/Emacs/.ssh when my public key was in /c/Users/NumberOverZero/.ssh
Deleting the Emacs ssh folder (which was empty) fixed my issue since ssh would then check my Users .ssh folder.
I'm getting Permission denied (publickey) when trying to git push heroku master.
A few things that makes this different from the posts below:
I have ssh working for github
I was able to successfully push to heroku last night
Since that push, I've made a single-line change to one js file, and committed and pushed. There have been no other changes.
The closest I could find was this post:
git clone heroku ssh permission denied
I've looked through the related issues (there's quite a few):
git push heroku master Permission denied (publickey). fatal: The remote end hung up unexpectedly
git push heroku master permission denied
git clone heroku ssh permission denied
https://stackoverflow.com/questions/13059076/git-push-permission-denied-publickey-windows-xp
heroku - rails - Permission denied (publickey)
I've tried:
heroku keys:clear
heroku keys:add
heroku keys:clear
*delete every key in .ssh*
heroku keys:add
*delete my application on heroku*
heroku keys:clear
heroku login (adds key for me)
heroku create
git push heroku master
fails
*delete the app on heroku*
delete keys in .ssh
heroku keys:clear
copy all files into a new repository
push new repository to github successfully
heroku login (adds github key for me)
heroku create
git push heroku master
fails
*delete the app on heroku*
heroku keys:clear
heroku login (adds key for me)
heroku create
heroku git:clone app app
fails
Any ideas? I've gone through all of the steps in the linked SOs - most of which were just people not running heroku:add or setting up ssh keys (which I've done in each of these).
I let heroku take the wheel most of the time, (instead of directly creating ssh keys) assuming that the built-in commands would do what they needed when there were no ssh keys present. It seems not.
EDIT: And now that I deleted the app, the new relic addon is alarming that the website is down. Trying to log in through their website asks me to log in through heroku. Which I can't find a way to do, since the app is gone. Is there a way to delete that addon now that I can't get to the app? heroku addons gives an error, so I don't think I'm getting to it through there.
EDIT #2: Added another step I tried - moved files into new repository and push to new application.
I had the same problem for Windows 7 box and found the solution here: http://www.gmarwaha.com/blog/2011/05/18/heroku-trouble-with-windows-and-ssh-keys/
Solution: Typically once you create the keys as mentioned above, two files – “id_rsa” and “id_rsa.pub” – are stored in the “.ssh” folder
within the user’s home folder. If you are working with linux that
seems to be good enough. But for the windows version of git that
doesn’t seem to cut it. It wants the keys to be stored inside the
“.ssh” folder within the “msysgit” installation folder as well. If you
don’t find a “.ssh” folder inside the “msysgit” installation folder,
feel free to create one. Once you drop these two key files there and
repeat the entire process, everything went as smooth and my
application got deployed in the heroku cloud and the world is again a
better place to live in.
In my case, I have to find where git.exe was installed, which is C:\Program Files\Git\. So here are the steps:
Create .ssh folder inside C:\Program Files\Git\
Copy id_rsa and id_rsa.pub from your home folder (C:\Users\username\.ssh\) to C:\Program Files\Git\.ssh\.
Try again with C:\dev\heroku\sample-app> git push heroku master.
Nice job linking to all the other things you've looked at and tried! (that will improve the responses you get, but still you should be prepared for a lot of 'have you tried...', and 'maybe it's ...' because this is a system/env issue that isn't on the normal flow)
You might have had something working in your local terminal session that has since been lost. (I've had this happen a bunch of times)
Things it might be:
your ssh keys on heroku
your ability to push up to heroku from that computer/network
something about your git repo
I ran into this once and it was driving me crazy. I hopped on my (FREE) cloud9 account, cloned some simple rails app from github and pushed it out to heroku, which helped me prove that my heroku account was fine, heroku itself was fine, but my local laptop had some issues in my configuration.
I think the issue was my username, but I don't remember. (moving to a different env and starting from scratch helped me realize the issue though)
The main reason you get this message is because you do not have ssh-keygen added to your environment variables.
This command is located in the bin-directory of Git program files.
You should add that bin directory to your environment variables.

Resources