Have a problem with connecting to CodeCommit with ssh.
It seems I do all that needs. generate key , give him access rights, put in AWS IAM pubkey for user with roles for code commit. create config file on local machine. Answer is always:
$ ssh git-codecommit.us-east-2.amazonaws.com
APKA5S53BOD356YJBIJT@git-codecommit.us-east-2.amazonaws.com: Permission denied (publickey).
Here is verbose ssh:
ssh -v git-codecommit.us-east-2.amazonaws.com
OpenSSH_8.5p1, OpenSSL 1.1.1k FIPS 25 Mar 2021
debug1: Reading configuration data /home/edopc/.ssh/config
debug1: /home/edopc/.ssh/config line 1: Applying options for git-codecommit.*.amazonaws.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Reading configuration data /etc/ssh/ssh_config.d/50-redhat.conf
debug1: Reading configuration data /etc/crypto-policies/back-ends/openssh.config
debug1: configuration requests final Match pass
debug1: re-parsing configuration
debug1: Reading configuration data /home/edopc/.ssh/config
debug1: /home/edopc/.ssh/config line 1: Applying options for git-codecommit.*.amazonaws.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Reading configuration data /etc/ssh/ssh_config.d/50-redhat.conf
debug1: Reading configuration data /etc/crypto-policies/back-ends/openssh.config
debug1: Connecting to git-codecommit.us-east-2.amazonaws.com [52.95.17.51] port 22.
debug1: Connection established.
debug1: identity file /home/edopc/.ssh/codecommit type 0
debug1: identity file /home/edopc/.ssh/codecommit-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.5
debug1: Remote protocol version 2.0, remote software version AWSCodeCommit U2F0LCAyMiBNYXkgMjAyMSAxNjowNDowOSArMDAwMFjNE4tTOciz86teVxk/4lERVeKLS9FdeSxYQXNw3s8tUj
debug1: compat_banner: no match: AWSCodeCommit U2F0LCAyMiBNYXkgMjAyMSAxNjowNDowOSArMDAwMFjNE4tTOciz86teVxk/4lERVeKLS9FdeSxYQXNw3s8tUjRTVkFCRVlTWHpNMjBLNnFzNXRuMG8vTElFWCtzSHg5T29MVDc2YUNUakk9
debug1: Authenticating to git-codecommit.us-east-2.amazonaws.com:22 as 'APKA5S53BOD356YJBIJT'
debug1: load_hostkeys: fopen /home/edopc/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: diffie-hellman-group-exchange-sha256
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: aes256-ctr MAC: hmac-sha2-256 compression: none
debug1: kex: client->server cipher: aes256-ctr MAC: hmac-sha2-256 compression: none
debug1: kex: diffie-hellman-group-exchange-sha256 need=32 dh_need=32
debug1: kex: diffie-hellman-group-exchange-sha256 need=32 dh_need=32
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(2048<8192<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_GROUP received
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: SSH2_MSG_KEX_DH_GEX_REPLY received
debug1: Server host key: ssh-rsa SHA256:3lBlW2g5xn/NA2Ck6dyeJIrQOWvn7n8UEs56fG6ZIzQ
debug1: load_hostkeys: fopen /home/edopc/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host 'git-codecommit.us-east-2.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /home/edopc/.ssh/known_hosts:1
debug1: rekey out after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 4294967296 blocks
debug1: Will attempt key: /home/edopc/.ssh/codecommit RSA SHA256:R3h4w103OgUGoySJKnFe5rxeqU0gB7nEuQW0zH8uD9E explicit agent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/edopc/.ssh/codecommit RSA SHA256:R3h4w103OgUGoySJKnFe5rxeqU0gB7nEuQW0zH8uD9E explicit agent
debug1: send_pubkey_test: no mutual signature algorithm
debug1: No more authentication methods to try.
APKA5S53BOD356YJBIJT@git-codecommit.us-east-2.amazonaws.com: Permission denied (publickey).
A recent release of OpenSSH removed less secure algorithms by default. CodeCommit does not yet support the latest recommended algorithms.
Edit the .config file for ssh by adding a section as follows:
Host git-codecommit.*.amazonaws.com
User REDACTED
HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa
This will enable ssh to use the "ssh-rsa" algorithms with CodeCommit.
Note that there is no need to change your id_rsa/id_rsa.pub file to use a different key type as some people have suggested. The key exchange algorithms are deprecated. Large RSA keys are unwieldy but still secure enough.