Having some issues with maintaining too many SSH keys in the same computer lately.
I have created two SSH keys in my computer for UserA(Company) and UserB(Personal). Both the ID's are created using different email ID
I am able to pull and push the code changes for UserA
But UserB is where I face trouble to push my code.
I am able to pull the code for UserB(Where repo is different than UserA)
While pushing the code I get the following error
ERROR: Permission to UserB/xxxxxx.git denied to UserA.
Please make sure you have the correct access rights
and the repository exists. ```
Feel bit strange to me. Can someone help me this ?
Starting from Git 2.3.0 you can use below command
GIT_SSH_COMMAND='ssh -i private_key_file' git clone user#host:repo.git
Solved !!
Created Gitconfig for personal and work using the following link,
https://medium.com/#trionkidnapper/ssh-keys-with-multiple-github-accounts-c67db56f191e
Sometimes you have the problem of too many keys stored in the ssh-agent.
Then the server refuses the connection after it offering too many keys.
This can be solved by force ssh to use only one specific key.
GIT_SSH_COMMAND='ssh -o IdentityAgent=none -i private_key_file' git <cmd>
Related
I'm curious if I can put a GitHub SSH key on a USB flash drive as a singular key and remove the other SSH keys from my GitHub. I've found one source, but it doesn't necessarily specify that it's for GH, here.
Any help is appreciated, thanks!
I have yet to experiment, just reading articles/watching YouTube videos to try and get a grasp on it.
As long as you are using a ~/.ssh/config file which points where your SSH key is, you can put said key pair wherever you want.
Host gh
Hostname github.com
User git
IdentityFile /mnt/usb-device/myKey
In your case, a nix copy --to file:///mnt/usb-device /path/to/key would be needed first.
However, the tutorial you are referring to is more about copying the key on an encrypted USB stick. Which might be a bit redundant, considering NixOS can be installed with Full Disk Encryption already.
I prefer to using ssh keys and there is a lot to learn for me always!
My current challenge is:
I am using Visual Studio 2019 and I have my organization's private repositories in guthub under the organization's name.
When i try to connect to one of the repositories under the name of my organization, i am getting this error:
permission denied (publickey)
I have generated ssh keys as follows:
id_rsa_personal#gmail
id_rsa_work_alias#organization
I also have a config file in ~/.ssh/config with contents as below:
#github personal
Host personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal#gmail
#github work
Host work
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work_alias#organization
In my visual studio 2019, under MenuBar-> Git-> Manage Remotes is setup to use ssh for fetch and push
Here is what my github dashboard looks like
As you can see, it has two entries one for my work alias and one for my organization
I mostly work on repositories under the Organization.
But while adding the ssh key contents to github, i added so under my work alias account
Now when i try to do a fetch from Visual Studio 2019, i get the error
permission denied (publickey)
Examining the Your Organizations menu option, i do not see a settings option.
So, in my case, should i be configuring visual studio 2019 to be using https:// to perform git operations? please clarify
To add to sborsky's comment, assuming everything is running with the current user (the one with ~/.ssh/config), the actual URL to use would be:
work:Organization/api-1.git
No need to repeat the user, which is already specified in ~/.ssh/config
Check first if it works with:
ssh -Tv work
You should see an error message, unless:
your account is not part of the organization
and/or you have not properly added the public key to your GitHub account.
This is a strange question, but I cannot find how I did this:
I have three computers, all of them with visual studio code and an account in gitlab. In two of them, my operation has been
git clone ___.git
cd folder
git init
git remote add origin ___.git
And then, every time I push,... I have to enter my id and pass.
But in my first computer, I did something that I don't need to enter the id and pass anymore, it just pushes without hassle.
Then, I thought I must have done something like this
https://git-scm.com/docs/git-credential-store
But when I look for .gitconfig, which I find in the /Users folder, there I only have my user.name (which is not the one of gitlab), the email (this one is the gitlab email) but no password entry. And I cannot find any other .gitconfig files anywhere. For sure I didn't set up any SSH key.
So here the question, what did I do?
Make sure to use the GCMfW: Git-Credential-Manager-for-Windows:
git config --global credential.helper manager
Then try again: that should cache your username / password, provided you are using an HTTPS (https://...) URL, not an SSH one.
I am new to both Git and Amazon EC2.
I want to clone my Github code to Amazon EC2 directly.
For that I have referred to the following URLs:
http://thelucid.com/2008/12/02/git-setting-up-a-remote-repository-and-doing-an-initial-push/
http://deductiveblog.in/2013/05/19/deploy-to-amazon-ec2-using-git/
How to push to git on EC2
I've performed the necessary changes suggested in the above URLs, but am still not able to get my data on Amazon EC2.
By following the above suggested steps, I can see one directory - but it does not display the data in it that I have in git & in my local.
So what should I do to clone all data in Amazon EC2?
I also want to know one other thing - is it possible that I can put my files directly in /var/www directory without creating .git?
Now in this, I am getting an error Permission denied (publickey). Fatal the remote end hung up unexpectedly.
For that I have checked my ssh keys as well and add it to github. I have a file authorized_keys for key and I have added the same key in github, but still it gives me a Permission denied error.
Can anyone give any suggestions how to resolve this?
You can just use the git clone command from your ec2 instance from the directory you want the repo cloned to.
git clone git://github.com/ryanb/railscasts-episodes.git
of course you need to alter the url part to your repo, this will create a folder with the files inside named after the repo in the current directory. If you want to clone the files inside the repo into the current directory do:
git clone git://github.com/ryanb/railscasts-episodes.git .
The Full Stop (.) or dot indicates the current directory in Unix.
I was able to create a key and connect to github following these instructions via the command prompt successfully:
https://help.github.com/articles/generating-ssh-keys
However, when I try to connect via Sourcetree and putty I cannot. I've tried:
generating a new key with the putty key generator (SSH-2 RSA)
entering a passphrase
saving the private key
saving the public key and adding a .pub extension
copying/pasting the key from the putty key generator window into github
attemping to refresh branches on a pull from my private github repository from my local repo using the SSH clone URL I got from github
I also tried opening the key generated from the github command line instructions and it wanted me to convert it to a putty-type key which I did and saved off, tried with that one. Also no luck.
What am I doing wrong?
In order to get it worked I ended up going to Tools -> Options -> SSH Client and changing it to OpenSSH. I generated and uploaded several different types of keys trying to get it work as well but I think this is what finally did it.
In my case, I needed to switch to a git or ssh based repo path rather than the https based repo path. This causes SourceTree to switch to SSH based authentication.
This setting can be found at Repository => Repository setting => Paths
Example:
Correct repo paths
git#github.com:<username>/<reponame>.git
or
ssh://git#github.com/<username>/<reponame>.git
(Note: if you are working with a repo that isn't yours, replace username with organization name)
Wrong repo path
https://github.com/<username>/<reponame>.git
HTTPS repo paths result in SourceTree trying to be extra smart and failing spectacularly. You get prompted for a username/password GUI dialog which will never work if you have 2 factor authentication enabled.
To login to Github account using SourceTree you may use access tokens. To create an access token follow these steps.
Go to Settings
Select Developer settings from left pane
Select Personal access token
Click on Generate new token button
Give it a name
Select scopes and generate token (save this token somewhere safe because you won't be able to access this token again)
Then in SourceTree app follow these steps (for Mac users, not sure about the other platforms)
Go to Preferences->Accounts
Click add button
Select GitHub from Host dropdown
Choose Basic from Auth Type dropdown and HTTPS from Protocol dropdown
Enter your GitHub username in Username field
Paste the access token generated in the previous process in the Password field
Click save and you're done
For Mac versions of SourceTree the Tools menu does not exist.
However, you can add the ssh key to your keychain in Mac OS. See: https://superuser.com/questions/879050/sourcetree-ssh-options-on-os-x
On Mac OSX, the native SSH client can use the built-in keychain directly. To add your private key to the keychain simply use the command:
ssh-add -K /path/of/private/key
As an example if your private key is stored at ~/.ssh and is named id_rsa, you would use the command:
ssh-add -K ~/.ssh/id_rsa
You will then be prompted for your passcode, which will be stored in your keychain. After this you should be ready for a password-less login.
You may want to consider switching from OpenSSH to Putty / Plink and use embedded Git instead of Git provided by host OS. Making ssh-agent work on Windows is a bit more complicated than clicking it out straight from the SourceTree and PuttyGen.
If you want to still use terminal to configure SSH and start ssh-agent please see bottom two steps.
For Sourcetree on MacOS I had to change from OAuth to Basic authentication, use "git" as the username (not my GitHub username), and generate the SSH key and input it into GitHub. Only then could I clone a GitHub repo via SSH in Sourcetree.