Git clone with shorthand SSH URL

Trying to clone with full SSH URL, e.g., git clone ssh://bitbucket.org/myaccount/myrepo.git fails with permission denied (publickey), but using shorthand SSH URL, e.g., git clone git@bitbucket.org/myaccount/myrepo.git works just fine. Furthermore, even doing something like the following fails:

ssh-agent bash -c 'ssh-add ~/.ssh/id_mykey_ed25519; git clone ssh://bitbucket.org/myaccount/myrepo.git'

EDIT:
I already have an entry of the following form in SSH config:

Host bitbucket.org
IdentityFile ~/.ssh/id_mykey_ed25519
IdentitiesOnly yes

>Solution :

Add User git:

Host bitbucket.org
    IdentityFile ~/.ssh/id_mykey_ed25519
    IdentitiesOnly yes
    User git

Now you can do

git clone ssh://bitbucket.org/myaccount/myrepo.git

without setting user explicitly.

Leave a Reply