很可能您已经在 HOST 中输入了 repo 的完整路径,而不是在“~/.ssh/config”中输入了 Code Commit Repo FQDN 公共端点:-
[user@example.com .ssh]# cat config
Host git-codecommit.ap-southeast-2.amazonaws.com/v1/repos/myrepoXYZ--> ??
User APKAEIBAERJR2EXAMPLE
IdentityFile ~/.ssh/codecommit_rsa
[user@example.com .ssh]# git clone ssh://APKAEIBAERJR2EXAMPLE@git-
codecommit.ap-southeast-2.amazonaws.com/v1/repos/myrepoXYZ
Cloning into 'my-webpage'...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository
exists.
[user@example.com .ssh]# cat config
Host git-codecommit.ap-southeast-2.amazonaws.com **---> CORRECT **
User APKAEIBAERJR2EXAMPLE
IdentityFile ~/.ssh/codecommit_rsa
[user@example.com .ssh]# git clone ssh://APKAEIBAERJR2EXAMPLE@git-
codecommit.ap-southeast-2.amazonaws.com/v1/repos/myrepoXYZ
Cloning into 'my-webpage'...
remote: Counting objects: 12, done.
Receiving objects: 100% (12/12), done.
[root@ip-10-0-6-161 .ssh]# ll
total 36
以下 AWS 文档中提供了详细步骤:-
在 Linux 上设置与 AWS CodeCommit 存储库的 SSH 连接的步骤
1. 第 1 步:- 在 EC2 上生成 ssh 密钥
[user@example.com .ssh]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
**/root/.ssh/codecommit_rsa**
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/codecommit_rsa.
Your public key has been saved in /root/.ssh/codecommit_rsa.pub.
The key fingerprint is:
SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The key's randomart image is:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2. 第 2 步:-
使用 ssh-keygen 创建您的凭证并将公有密钥上传到“AWS CodeCommit 的 SSH 密钥”部分中的 IAM 用户
[user@example.com .ssh]# ll ~/.ssh/
total 36
-rw------- 1 root root 1679 Mar 16 02:06 codecommit_rsa
-rw-r--r-- 1 root root 432 Mar 16 02:06 codecommit_rsa.pub ----> *** upload to IAM ***
3. 第 3 步:-
你的 ~/.ssh/config 文件应该是:-
[user@example.com .ssh]# pwd
/root/.ssh
[user@example.com .ssh]# cat config
Host git-codecommit.ap-southeast-2.amazonaws.com
User APKAEIBAERJR2EXAMPLE
IdentityFile ~/.ssh/codecommit_rsa
注意:您的 AWS CodeCommit 的 DNS FQDN 公共端点可以是任何东西,上面是悉尼:ap-southeast-2 区域,从 codecommit 控制台的克隆下拉列表中检查您的。或者只使用通配符来允许代码提交
AWS CodeCommit 克隆 URL - SSH