Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Push no longer works: unauthorized

tim_in_palmer November 13, 2019 edited

FYI: Retired programmer, linux platform, bash terminal. Some experience with SSH, new to git and bitbucket. Have followed a tutorial which steps through creating and pushing to repositories. Repositories were deleted and a new one created. I have generated a new SSH key, ssh-agent and ssh-add were used as per the bitbucket instructions and added public key to my bitbucket profile.

I can 't even manage to execute an initial push to that new repository. The following code was attempted with user and repository name obfuscated. (please advise me if such obfuscation is not necessary).

git remote add origin git@bitbucket.org:myusername/mypository.git

fatal: remote origin already exists.

git remote set-url origin git@bitbucket.org:myusername/mypository.git

returns nothing and appears to log me in.

the following three commands are all unsuccessful:

git push -f origin master

Unauthorized
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

 git push -u origin master

Unauthorized
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

 

git push -u origin --all

Unauthorized
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

.... and same issue with -f flag.

Please advise, I am also unfamiliar with formatting protocols here. So Sorry.

I'm speculating that my key may not be readable, but if so, don't know where to change settings.

Thanks,

Tim

2 answers

2 accepted

0 votes
Answer accepted
tim_in_palmer November 13, 2019

Thank you Daniil:

for ssh -T  the response is as follow:

ssh -T git@bitbucket.org
authenticated via a deploy key.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

This deploy key has read access to the following repositories:
tim_in_palmer/helloworld

thanks again

Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 13, 2019

Oh, so this explains what's wrong.

You have configured another SSH key in the repository – this one is called access or deploy key and is scoped to the repository, not to your account. It has read-only access to the repository, and this explains why you were not able to push. This type of key is designed to be used by external CI/CD systems to build and deploy your repository. You shouldn't be using that key to develop against the repository.

Now, the output of the SSH command you ran suggests that you've added the access SSH key to the SSH agent, and Git is using it to authenticate with Bitbucket. What you need to do now is remove the access key from your SSH agent (and maybe even unregister it – do you need it?) and add the correct one that you've registered in your account settings.

Does this make sense? Let me know if you have any questions.

Cheers,
Daniil

Like newaz likes this
tim_in_palmer November 13, 2019 edited

Darn it!

It looks like what I did was to enter my repository and choose Access Keys from the  repository  settings.  I will delete that key and start over using Settings->Ssh Keys for my account.  I must wait until tomorrow based on my time zone.

Perhaps you can answer one other question:

Need I use a password for the key?

If not, I would not need to use ssh-agent/ssh-add.

Thanks for your help. I will resume muddling through tomorrow.

cheers

Like Daniil Penkin likes this
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 13, 2019

I will delete that key and start over using Settings->Ssh Keys for my account.

I can actually see a public SSH key configured in your account already, so you might have the private part of it somewhere locally. But yeah, you can always recreate it and register the new one.

Need I use a password for the key?

The password on the SSH key is for security of the key itself only. As in, if a malicious person steals the key from your machine (it's just a file on the disk, right?), and the key isn't password protected, that person then can use such key straight away and act as you wherever that key is registered. If the key is password-protected, an attacker would need to also know the password to decrypt the key first to be able to use it.

This is why it is generally recommended to password-protect SSH keys, as well as use different SSH keys for different systems so that if one key is compromised, no other systems are at risk of malicious access.

All in all, you're not required to have password for the key, but generally it's a good habit to password protect it.

Hope this helps.

Cheers,
Daniil

tim_in_palmer November 14, 2019

G'Day all:

I have successfully pushed to the bitbucket repository. Yay!

I would greatly appreciate it if I were referred to a location where update protocols are discussed and/or examples.

I've successfully made an update but I want to make sure that I am invoking the appropriated commands.

Kudos to Daniil :)

0 votes
Answer accepted
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 13, 2019

Hello @tim_in_palmer,

Thanks for reaching out, I'm happy to help.

So all versions of git push you're trying to execute hit the very same error: git can't authenticate your request with Bitbucket. I can see your attempts to push in the logs, which means that you're using the correct remote URL.

git remote add origin git@bitbucket.org:myusername/mypository.git
fatal: remote origin already exists.

git remote set-url origin git@bitbucket.org:myusername/mypository.git
returns nothing and appears to log me in.

Just a note here: git remote command doesn't log you in. In fact, that command doesn't make any requests, it only changes local repository configuration. Specifically, it registers/updates/deletes a remote – which is a named pointer to some external hosting service, like Bitbucket.

So the first command returned an error because you tried to add remote called origin, but it was already registered. The second command was to update the URL for existing remote origin, so did the thing and returned nothing. Note that if you clone a repository from Bitbucket (rather than creating it locally), you don't need to update any remote URLs for that repo to be able to push back to Bitbucket, they're all preconfigured for you.

Now, let's check if you have configured SSH key properly. I can see your public key in Bitbucket, so the question is now if it is the right one and if you have the corresponding private key configured locally. Run the following command:

ssh -T git@bitbucket.org

If everything is set up properly, you should see something like this:

logged in as <your_username>
You can use git or hg to connect to Bitbucket. Shell access is disabled

If you get something else at this point, this page might help with finding the cause and resolution.

Let me know what you find, and we'll continue from there.

Cheers,
Daniil

Suggest an answer

Log in or Sign up to answer
TAGS
loom essentials certification, loom training, get certified in loom, atlassian certification, loom async video, video messaging skills, atlassian learning, loom for teams, online certification, loom badge, loom for business, atlassian education

Get Certified in Loom! 🧑‍🎓

Time to up your Loom game! The new Loom Essentials Certification is here! Show off your skills, learn pro tips, and get officially recognized. Perfect for taking your video messaging to the next level.

Learn more
AUG Leaders

Atlassian Community Events