Search code examples
gitversion-controlbitbucketatlassian-sourcetree

Always need to renew ssh-keys working with Bitbucket from two machines


I've never had any problems working with my repos hosted on Bitbucket using SSH connection with a generated keypair. But since I'm accessing my repos from two different machines (e.g. home machine, work machine), I always get

Permission denied (publickey).fatal: Could not read from remote repository.

everytime I switch machines. So my current not so great workaround is to delete my current key with

rm -r .ssh

(I'm just using one) and then generate a new one, either using Sourcetree or Terminal. Then I remove the old key for the machine I'm using from my Bitbucket Account and paste in the new key.

This has been working since, but there has to be a better solution. I've browsed the Bitbucket docs, but it just says to add a new key for every machine, which is accessing the repos and obviously this it not working. I'm sure I'm missing something. Thanks for any help!


Solution

  • So here is a link to a guide on how to fix that problem.

    https://github.com/jirsbek/SSH-keys-in-macOS-Sierra-keychain

    As described in the comments, Apple changed SSH behavior in Sierra/High Sierra. Theres a Sourcetree issue with status 'resolved' about this topic (https://jira.atlassian.com/browse/SRCTREE-4499), so Sourcetree adds keys to .ssh/config with the needed flags since 2.7.2 but still this hasn't worked for me. I needed to add ssh-add -Ato my launch agents.