Forums

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

How do I configure crontab to git push with SSH-keys?

Jonas Tidström
Contributor
August 29, 2021

I have a script that automatically adds, commits and pushes to Bitbucket. It runs as expected and it backs up my Obsidian folder containing markdown files.

I want to run this script through crontab but I don't fully succeed. Adding and committing works as expected, but when I try to connect to Bitbucket I get:

fatal: could not read Password for 'https://---@bitbucket.org': Device not configured

 It seems to me that cron can't access my credentials. Now, I am not sure how to tackle this as I am not 100% sure how the credentials are handled...  When I was setting up my credentials I followed this guide (for MacOS): https://support.atlassian.com/bitbucket-cloud/docs/set-up-an-ssh-key/

With that background: how do I tell, either in crontab or my script, to use the credentials (that I think are stored in my keychain).

Help is much appreciated!

 

 

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 3, 2021

Hi Jonas,

If you want to use SSH for interacting with Bitbucket repos, apart from setting up SSH keys, you'll also need to use the SSH URL for the repo.

Based on the error that you get, it looks that you're using an HTTPS URL instead, https://---@bitbucket.org

If you specify the URL in your script, you'll need to replace the URL in the script from HTTPS to the SSH one, which has the format

git@bitbucket.org:<workspace-id>/<repo-slug>.git

If you don't specify the URL in your script, I assume that the script is using the URL defined for the clone of this repo on your machine, so you'll need to change that.

If you navigate to the clone directory from a terminal on this machine, you can run

git remote -v

and the output should look as follows:

origin https://<Bitbucket_username>@bitbucket.org/<workspace-id>/<repo-slug>.git (fetch)
origin https://<Bitbucket_username>@bitbucket.org/<workspace-id>/<repo-slug>.git (push)

You can change that URL to an SSH one with the command

git remote set-url origin git@bitbucket.org:<workspace-id>/<repo-slug>.git

If your remote name is different than 'origin', replace 'origin' with your remote name.
<workspace-id> should be replaced with the workspace id of the workspace that owns this repo
<repo-slug> should be replaced with the repository slug

Please feel free to let me know if you have any questions.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events