Git Push - Permission Denied - authentication

I'm new to GitHub and experimenting with my first repo. I'm using my Mac which was used by my friend for few days. Now the problem is, as I tried to push my first commit, I see an error that says -
remote: Permission to myUserName/repo.git denied to myFrndsUserName.
fatal: unable to access 'https://github.com/myUserName/repo.git/': The requested URL returned error: 403
I understand that my friend has used his credentials earlier and those are mismatching with my credentials as I tried to push my code. In best case, I would like to replace my friend's credentials with mine and I don't have to give my username and password everytime for different repos that I create in the near future.
Can somebody help me with this? Thank you.

Try this:
Open terminal :
Enter: ls -al ~/.ssh to see if existing SSH key are present in your case may be your friend have removed your previous SSH key.
if dont have any public or private key pair or if you do not want to use those keys available you have to generate new one.
$ ssh-keygen -t rsa -b 4096 -C "your_email#exaple.com"
# Creates a new ssh key, using the provided email as a label
When you are prompted to "Enter a file which to save the key" press Enter. this accepts the default file location.
At the prompt, Type a secure passphrase. For more info see "Working with SSH Key"
Add SSH key to your GitHub account
Copy the SSH key to clipboard.
If your SSH key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don't add any newlines or whitespace.
$ pbcopy < ~/.ssh/id_rsa.pub
To follow further steps click here
Let me know if this doesn't work out properly

Related

Microsoft TFS ssh cloning fails

I am trying to clone a repo from a project on my Team Foundation Server domain. I have created an SSH key under my profile security. However after accepting the repo's key I am still requested to sign in with a password and the authentication fails:
git clone ssh://mydomain#mydomain.visualstudio.com:22/Project/_git/project-repo
Cloning into 'project-repo'...
mydomain#mydomain.visualstudio.com's password:
Permission denied, please try again.
mydomain#mydomain.visualstudio.com's password:
Permission denied, please try again.
mydomain#mydomain.visualstudio.com's password:
Permission denied (password,publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I have tried both my visualstudio.com password and SHH key password none of which work.But Why is it asking me for a password?
The prerequisite to use ssh for VSTS as below:
Generate ssh key. In git bash, use ssh-kengen in git bash -> select path to save the key -> enter passphrase (if you don’t want passphrase, press enter direcly).
Add the content of .ssh/id_rsa.pub file in KeyData in VSTS SSH public keys (profile -> security).
For your situation, it seems the conent of .ssh/id_rsa.pub is not same with VSTS SSH public keys. So you'd better do step1 and setp2 above and ten clone again with ssh protocol.
The way I resolved this was by deleting and recreating my id_rsa.pub without a password.
The default authentication mode when using SSH is the private key. Whenever that fails for some reason, the ssh-agent falls back to username and password based authentication.
There are several reasons why the default key based authentication might have failed. Following are the most common cases :
a) The ssh-agent cannot find the default private key file which is id_rsa, and no other key path is specified explicitly.
b) The public key stored in the server is incorrect.
c) The path you're trying to clone is incorrect.
In any case, to troubleshoot the issue first of all execute the git clone command with verbose logging with the command :
GIT_TRACE=1 GIT_SSH_COMMAND="ssh -vvv" git clone ssh://pathToYourRepo
You can go through each step in the log to get an intuition of what the issue might be.
Troubleshooting in case of (a)
Make sure you have the default key name id_rsa in the .ssh directory. You might have specified some different keyname when generating the key with ssh-keygen command or maybe there isn't any key at all).
In case you want to specify a different key for authentication, use the following command :
ssh-agent bash -c 'ssh-add ~/.ssh/anotherKey; git clone ssh://pathToYourRepo'
Troubleshooting in case of (b)
Make sure there aren't extra white spaces when storing the public key in the server.
Troubleshooting in case of (c)
Make sure you aren't trying to clone with the https version of the repository path.

Cannot add ssh key. ssh-add returns 1

I've got to install a public key on my server so that a remote script can ftp files to my server.
I placed the public key in my ~/.ssh directory and made sure that ssh-agent is running and that the relevant env variables are set correctly.
I made sure that the permissions on the public key are set to 600.
I ran ssh-add and it didn't add the public key. I ran ssh-add and supplied the name of the public key and it asked for the pass phrase. Since the user who generated the public key did so without a pass phrase I left it blank and hit enter. Nothing happened and echo $? returns 1.
I renamed the public key to identity. I ran ssh-add again and it tried to add the key, again asking for a pass phrase. Again I hit enter and nothing happened, echo $? still returns 1.
I've found several answers that say ssh-add will add private keys if you supply arguments and that you have to run it without arguments. This doesn't seem to be the reality. I've tried the key in both the ssh2 format and the openSSH format.
I also read that I can add the key manually. I've read that the file is supposed to be in ~/.ssh and I've read different sources say that it had to be authorized_keys, authorized_keys2 and known_hosts. I tried all three and the remote script still cannot log in.
The format I used for the entry in authorized_keys was "ssh-rsa AAAAB3...="
Permissions for all three files are 600.
I'm completely lost.
I'm on Solaris 10.
My problem was that I had an = at the end of the line in my authorized_keys file.
I had added the = because it was how the authorized_keys file on another server I used was written. I don't know why it was like that or why I assumed it was a necessary part or the format but removing that let the remote user login without any problem.

Why do I still have to enter password after I entered ssh-agent and ssh-add?

I'm learning Ansible, in a setup document : http://docs.ansible.com/intro_getting_started.html
It says if I don't want to enter password every time, I can do :
$ ssh-agent bash
$ ssh-add ~/.ssh/id_rsa
I did it, but how come I still have to enter password every time ?
Then it says "you may wish to use Ansible’s --private-key option", but I can't find any document on that. Whay's that for and how to do it ?
I'm not sure about Ansible, but I know a bit about how ssh keys work
When you generate a new SSH key with the ssh-keygen command (which by default goes to the ~/.ssh/id_rsa file), it asks you to put in a passphrase(password)
Whenever you use that key, it will ask you for that passphrase.
If you create a new key with
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa): /home/YOUR_USERNAME/.ssh/id_rsa_nopass
Enter passphrase (empty for no passphrase): [just press enter, don't type anything]
Enter same passphrase again: [just press enter again]
This will create both an id_rsa_nopass private key file, and an id_rsa_nopass.pub public key file in the directory you chose (/home/user/.ssh)
You should then be able to use the following command, assuming ansible is set up to use your ssh keys correctly
$ ssh-add ~/.ssh/id_rsa_nopass
NOTE: Using an ssh key without a passphrase can be dangerous, as anybody can access your device and connect without knowing your password. If you don't mind this, then a no-passphrase ssh key is a good way to avoid typing a password everyone
edit: Just looked into Ansible a bit, it's basic setup is just to run a command on an ssh server, right?
In which case, you may need to add your public key to whichever server you are connecting to, this can usually be done via the command
ssh-copy-id -i /path/to/your/public/key/file yourname#yourserver.com -p your_server's_ssh_port
For example, to authorize the id_rsa_nopass key from earlier to the account foobar on the server example.org, with ssh port 10022 you would do
ssh-copy-id -i ~/.ssh/id_rsa_nopass.pub foobar#example.org -p 10022
This will prompt you for the password to foobar#example.org, upon filling in the password it will authorize that public key to connect to that server, and since id_rsa_nopass has no passphrase, you should now be able to connect without any password prompt

Permission Denied on SSH on Bazaar

I'm new to Bazaar. I'm trying to setup my SSH Keys, but I'm always getting "Permission Denied".
Here are the things I did:
Open PuTTYgen
Click "Generate"
Move around the mouse pointer
Add a passphrase "password"
Click the "Save public key", and save the public key
Click the "Save private key", and save the private key "Private Key.ppk"
Login and go to https://launchpad.net/~paulmarkcastillo/+editsshkeys
Copy the Public Key from PuTTY Key Generator window, and paste it to the Launchpad
Click "Import Public Key"
I received an email about the new import (New SSH key added to your account).
Open Pageant
Click "Add Key"
Browse thru my "Private Key.ppk"
Enter my passphrase "password"
Open command line
Type "bzr launchpad-login paulmarkcastillo"
Type "bzr info lp:bzr"
Here is the output :
Permission denied (publickey).
ConnectionReset reading response for 'BzrDir.open_2.1', retrying
Permission denied (publickey).
bzr: ERROR: Connection closed: Unexpected end of message. Please check connectivity and permissions, and report a bug if problems persist.
How can I diagnose the problem?
To tell Bazaar to use putty, and thus access to the key cached by pageant, you need to set the BZR_SSH environment variable to point to plink.exe, for example:
set BZR_SSH=C:\Program Files\PuTTY\plink.exe
Also, it's probably not a problem, but I urge you to create a new key with 2048 bits encryption. When you open puttygen.exe, change the Number of bits in a generated key box from 1024 to 2048. 1024-bit keys are known to be insecure and automatically denied in modern systems. You will be more future proof with 2048-bit keys.
Finally, if the above still doesn't work, I recommend the following sanity check:
bzr config --remove launchpad_username --scope=bazaar
bzr info lp:bzr
This should work, regardless of your key setup. Later you can add back your launchpad username configuration by running bzr lp-login paulmarkcastillo again.
UPDATE
If you are using bzr from Git Bash or cygwin then be careful how you set BZR_SSH. If you set it using the environment variables screen, that should be fine. If you set it somewhere else, for example in ~/.profile, then you need to write it differently, for example in Git Bash:
BZR_SSH='/c/Program Files/PuTTY/plink.exe'
# or probably this works too
BZR_SSH='C:\Program Files\PuTTY\plink.exe'

ssh -T git#github.com Permission denied (publickey)

I tried to push my blog (Octopress) to github and got this error:
MacBook-Air:octopress bdeely$ git push origin source
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I generated an SSH key, saved it, and even linked it with my GitHub account in the SSH key settings, but I went ahead and checked the status and got the same error:
MacBook-Air:.ssh bdeely$ ssh -T git#github.com
Permission denied (publickey).
In addition to this, I checked github's help page, did the following and got this error message:
MacBook-Air:~ bdeely$ ssh-add -l
The agent has no identities.
Does anyone know what is wrong and how I can fix this?
On OSX, if you type
ssh-add -l
and you get back "no identities", that means your ssh agent does not have any identities loaded into it. Oftentimes, when the mac reboots, you have no identities.
I add mine back after a re-boot by explicitly running
ssh-add
This loads a default identity from ~/.ssh/id_rsa
You can also use the ssh-add command with a specific identity
ssh-add ~/foo/bar/is_rsa
After you add your identies, you can seem them all listed by typing
ssh-add -l
Make sure you have at least one listed.
Follow the commands:
mkdir ~/.ssh //in case that the folder doesnt exist...
cd ~/.ssh
ssh-keygen -t rsa -C "youremail#somewhere.gr"
#hit enter when asks for file to save the key.
#enter the passphrase
At last copy the id_rsa.pub into your github account.
Try this in your terminal:
eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa
enter your passphrase if any and it should work. Hope this helps :-)
I hope this helps you:
I was having the identical problem and about to take my own eyes out with insane frustration; nothing online led me to an answer and I was trying to use the git push command without specifying the URL exactly (which could also solve the problem I believe), so I didn't see how the connection was failing.
I had set up my .ssh/config correctly for two users with two different keys, even using IdentitiesOnly yes which is supposed to override ssh-agent that was automatically supplying the WRONG ssh identity.
I finally realized the problem as I examined the local repository configuration - it was the entry
[remote "origin"]
url = git#github.com:{my-username}/{my-repo-name}.git
My configuration in .ssh/config file was using the same HostName github.com entry for both users and I'm completely new to all this so I didn't realize that to correctly override ssh-agent, I had to specify the exact URL or else the specific identities in my .ssh/config file would be ignored and the first key that ssy-agent listed (which was the wrong one my my case) would be used by default.
I fixed this by changing the local repo URL to url = git#github-personal:{my-username}/{my-repo-name}.git, where I had set Host github-personal as the identity in my .ssh/config.
Another way to solve this would be specifying the user in the URL in the git push command itself, or even better, a solution described here in a post AFTER solving this my own crappy way:
https://superuser.com/questions/272465/using-multiple-ssh-public-keys
I can't believe that no official source could offer a solution for or even properly explain this edge-case that seems really common (accessing two different github accounts from one machine with SSL).
I experienced the same problem. The reason was that I moved the key-files to another folder; it worked successfully when I moved them back to where they were originally.