I have my ssh identities added at the end of the .bashrc script, as the server says here when I log in, Agent is running with pid 8411 and all of the identitias are added.
As is also evident from the console below, I can not use my identities. In order to use them, I need to type a command to start the ssh agent (which now receives a new pid 8531) and also type the command to add the identity to the agent (again?), and only then will git recognize the identity and allow to pull the repo.
What is going on here, what am I doing wrong?
Last login: Sat Jul 1 11:51:58 2023 from 162.243.190.66
Agent pid 8411
Identity added: /root/.ssh/id_ed25519 ([email protected])
Identity added: /root/.ssh/id_ed25519_api_requests ([email protected])
Identity added: /root/.ssh/id_ed25519_airspace_sweden ([email protected])
Identity added: /root/.ssh/id_ed25519_hwx ([email protected])
root@DR2-sweden-internal-api:~# cd /var/www/html
root@DR2-sweden-internal-api:/var/www/html# ls
aircraft airspace airspace-sweden drones index.html
root@DR2-sweden-internal-api:/var/www/html# git clone [email protected]:domain/myrepo-api-out-HemsWX.git
Cloning into 'myrepo-api-out-HemsWX'...
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
root@DR2-sweden-internal-api:/var/www/html# eval "$(ssh-agent -s)"
Agent pid 8531
root@DR2-sweden-internal-api:/var/www/html# ssh-add ~/.ssh/id_ed25519_hwx
Identity added: /root/.ssh/id_ed25519_hwx ([email protected])
root@DR2-sweden-internal-api:/var/www/html# git clone [email protected]:domain/myrepo-api-out-HemsWX.git
Cloning into 'myrepo-api-out-HemsWX'...
remote: Enumerating objects: 91, done.
remote: Counting objects: 100% (91/91), done.
remote: Compressing objects: 100% (65/65), done.
remote: Total 91 (delta 35), reused 79 (delta 23), pack-reused 0
Receiving objects: 100% (91/91), 20.14 KiB | 2.88 MiB/s, done.
Resolving deltas: 100% (35/35), done.
This is at the end of my ~/.bashrc
#add github deploy keys to agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
ssh-add ~/.ssh/id_ed25519_api_requests
ssh-add ~/.ssh/id_ed25519_airspace_sweden
ssh-add ~/.ssh/id_ed25519_hwx
------- UPDATE (for Ulrichs comment) ----------
So I notice that the first of the four identities is usable. The -v gave a whole lot of debug lines =)
debug1: Connecting to github.com [140.82.121.3] port 22.
debug1: Connection established.
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa_sk type -1
debug1: identity file /root/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type 3 // <------ one of my 4 identity files
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: identity file /root/.ssh/id_ed25519_sk type -1
debug1: identity file /root/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /root/.ssh/id_xmss type -1
debug1: identity file /root/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.7
Or is that just listing they type of identity files it looks for? Because further down I got this:
debug1: Will attempt key: /root/.ssh/id_ed25519 ED25519 SHA256:pHUHZ1LHAiGC0z---------------------- agent
debug1: Will attempt key: [email protected] ED25519 SHA256:6U2cH2OBWTIuVGx---------------------- agent
debug1: Will attempt key: [email protected] ED25519 SHA256:o+a6AiJJzpLFqjV---------------------- agent
debug1: Will attempt key: [email protected] ED25519 SHA256:Yz4Ayq8x/6bqf9D---------------------- agent
debug1: Will attempt key: /root/.ssh/id_rsa
debug1: Will attempt key: /root/.ssh/id_dsa
debug1: Will attempt key: /root/.ssh/id_ecdsa
debug1: Will attempt key: /root/.ssh/id_ecdsa_sk
debug1: Will attempt key: /root/.ssh/id_ed25519_sk
debug1: Will attempt key: /root/.ssh/id_xmss
So it seems that it attempts keys, but why is there only a path on first one of them? The others have no path but only my email adress?
debug1: Will attempt key: /root/.ssh/id_ed25519 ED25519 SHA256:pHUHZ1LHAiGC0z---------------------- agent
debug1: Will attempt key: [email protected] ED25519 SHA256:6U2cH2OBWTIuVGx---------------------- agent
debug1: Will attempt key: [email protected] ED25519 SHA256:o+a6AiJJzpLFqjV---------------------- agent
debug1: Will attempt key: [email protected] ED25519 SHA256:Yz4Ayq8x/6bqf9D---------------------- agent
------------ UPDATE (for aviro's comment) ---------
the agent is indeed running with a PID of 165201. However adding the identity manually to that agent is not helping as seen below. Also as seen below, running eval on the agent again, and then manually adding the identity does the trick. I notice that there is only one agent running, so the PID is replaced with a new PID when running eval on the agent.
root@DR2-sweden-internal-api:/var/www/html/hwx# echo $SSH_AGENT_PID;
165201
root@DR2-sweden-internal-api:/var/www/html/hwx# ps -fp $SSH_AGENT_PID
UID PID PPID C STIME TTY TIME CMD
root 165201 1 0 08:14 ? 00:00:00 ssh-agent -s
root@DR2-sweden-internal-api:/var/www/html/hwx# ssh-add ~/.ssh/id_ed25519_hwx
Identity added: /root/.ssh/id_ed25519_hwx ([email protected])
root@DR2-sweden-internal-api:/var/www/html/hwx# git fetch
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
root@DR2-sweden-internal-api:/var/www/html/hwx#
root@DR2-sweden-internal-api:/var/www/html/hwx# eval "$(ssh-agent -s)"
Agent pid 166484
root@DR2-sweden-internal-api:/var/www/html/hwx# ssh-add ~/.ssh/id_ed25519_hwx
Identity added: /root/.ssh/id_ed25519_hwx ([email protected])
root@DR2-sweden-internal-api:/var/www/html/hwx# git fetch
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 3 (delta 2), reused 3 (delta 2), pack-reused 0
Unpacking objects: 100% (3/3), 721 bytes | 721.00 KiB/s, done.
From github.com:Naviation/dronerequest-api-out-HemsWX
7bdda64..c620151 master -> origin/master
* [new branch] version_1.2 -> origin/version_1.2
root@DR2-sweden-internal-api:/var/www/html/hwx#
ssh -vv [email protected]with the initial agent so we can see more detail.-vflag suggested by @UlrichSchwarz, please also check if your agent is running by running the command:echo $SSH_AGENT_PID; ps -fp $SSH_AGENT_PID. If i your agent is running, please try to add the key to the agent in your shell without runningeval "$(ssh-agent -s)"before. This will help understand if the problem is with the agent not running/stopping after.bashrc, and in case it is running, if it responds to newssh-addcommands.~/.ssh/id_ed25519is one of the default pathnamessshitself tries.