0

In my pc I setup a file named ~/job/ssh/config

Host bitbucket
 HostName bitbucket.org
 IdentityFile ~/job/ssh/rsa_key
 user git
 IdentitiesOnly yes

and in my ~/.ssh/config

~/.ssh/config 
Include /home/pcmagas/job/ssh/config

And the folder ~/job/ssh has the following settings:

-rw------- 1 pcmagas pcmagas  191 Σεπ  15 10:57 config
-rw------- 1 pcmagas pcmagas 3414 Σεπ  15 10:45 rsa_key
-rw------- 1 pcmagas pcmagas  761 Σεπ  15 10:45 rsa_key.pub
-rw------- 1 pcmagas pcmagas  419 Αυγ  28 15:32 work
-rw------- 1 pcmagas pcmagas  109 Αυγ  28 15:32 work.pub

By doing:

$ ssh bitbucket
PTY allocation request failed on channel 0
authenticated via ssh key.

You can use git to connect to Bitbucket. Shell access is disabled
Connection to bitbucket.org closed.

Also I can:

 ssh -i ~/job/ssh/rsa_key [email protected]
PTY allocation request failed on channel 0
authenticated via ssh key.

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

I can connect to bithubket.

Firthermore by doing:

GIT_SSH_COMMAND='ssh -i ~/job/ssh/rsa_key -o IdentitiesOnly=yes' git clone [email protected]:exampe/myproj.git

I can clone it:

Γίνεται κλωνοποίηση μέσα στο 'myproj'...
remote: Enumerating objects: 210004, done.
fetch-pack: unexpected disconnect while reading sideband packet

But I cannot without the variable. Any ideas what's wrong?

As a means of mitigation I also tried to comment the inclide line in ~/.ssh/config and placing these stuff in to ~/.ssh/config directly:

Host bitbucket
 HostName bitbucket.org
 IdentityFile ~/job/ssh/rsa_key
 user git
 IdentitiesOnly yes

Furthermore I've run these commands as well:

chmod 400 ~/job/ssh/*
chmod +w ~/job/ssh/config
2
  • 1
    1. Your keyfile is not in the default location (~/.ssh/) so it's not picked up by ssh ( and git by extension) itself without you specifying it's path 2. You appear to not be running an instance of ssh-agent with your key loaded 3. You could workaround the variable by using git config core.sshCommand.
    – Panki
    Sep 15, 2023 at 9:09
  • But what is the point if hgaving a ssh config if I cannot specify the key into other directory. Sep 15, 2023 at 9:28

1 Answer 1

0

In order for this setting to work rename the entry:

Host bitbucket
 HostName bitbucket.org
 IdentityFile ~/job/ssh/rsa_key
 user git
 IdentitiesOnly yes

Into:

Host bitbucket.org
 HostName bitbucket.org
 IdentityFile ~/job/ssh/rsa_key
 user git
 IdentitiesOnly yes

This will trick the ssh-agent to use the key located upon ~/job/ssh/rsa_key instead of the ones located into ~/.ssh.


But I have seperate config file

This works both if the entry is in:

  • ~/job/ssh/config
  • ~/.ssh

For the first to work you must place the line:

Include /home/pcmagas/job/ssh/config

At ~/.ssh/config.

3
  • 2
    I don't think ssh-agent is going to be involved here unless you use AddKeysToAgent. By specifying IdentitiesOnly, you're explicitly telling SSH to ignore the keys available via the agent.
    – muru
    Sep 15, 2023 at 10:45
  • But in my case worked regardless if keys in ssh-agent or not. Sep 15, 2023 at 11:04
  • Eh? Of course it will work, because you are explicitly telling it to ignore keys in ssh-agent.
    – muru
    Sep 15, 2023 at 11:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .