我在 .bashrc 脚本末尾添加了 ssh 身份,正如服务器在我登录时所说的那样,代理正在使用 pid 8411 运行,并且所有身份都已添加。
从下面的控制台也可以明显看出,我无法使用我的身份。为了使用它们,我需要输入命令来启动 ssh 代理(现在它收到新的 pid 8531),并输入命令将身份添加到代理(再次?),只有这样 git 才会识别身份并允许拉取存储库。
这是怎么回事,我做错了什么?
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.
这是我的 ~/.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
------- 更新(乌尔里希评论) ----------
所以我注意到四个身份中的第一个是可用的。 -v 给出了很多调试行 =)
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
或者这只是列出了它要查找的身份文件类型?因为再往下我得到了这个:
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
所以看起来它尝试了密钥,但为什么其中第一个密钥上只有一条路径?其他人没有路径,只有我的电子邮件地址?
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
------------ 更新(aviro 的评论)---------
该代理确实正在以 PID 165201 运行。但是,手动将身份添加到该代理并没有帮助,如下所示。同样如下所示,再次在代理上运行 eval,然后手动添加身份即可解决问题。我注意到只有一个代理正在运行,因此在代理上运行 eval 时,PID 被替换为新的 PID。
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#