How to upload new repo to BitBucket using git with SSH on Linux command line only?

How to upload new repo to BitBucket using git with SSH on Linux command line only?

Steps I've taken:

ssh-keygen my key

ssh-add -K ~/.ssh/<private_key_file> my key

Add the public key to my BitBucket Account settings

git config --add --global core.sshComand 'ssh -i ~/.ssh/id_rsa' add my SSH key to git config

And still when I try to push my repo git is asking me for username/password. What did I do wrong? Or do I have to specify a git option to push using SSH key instead of basic auth?

git version is 2.37.1 OS version is Ubuntu LTS

答案1

SSH keys only work with SSH remotes – they cannot be used if the Git repository is configured to push to an "https://" URL (because that's not SSH).

Use git remote set-url to change it to the corresponding SSH address. For BitBucket, it's shown in the repository's "Clone" popup after you select 'SSH' in the corner menu. For example:

相关内容