AWS CodeCommit SSH Configuration: How to Connect and Clone Repositories

Connect with AWS CodeCommit via SSH: Configuration Guide

Prev Question Next Question

Question

A new employee joined a company where AWS CodeCommit manages code repositories in several AWS regions.

In order to connect with CodeCommit by SSH, he installed the latest version of GIT in a Linux machine, created a key pair via ssh-keygen and uploaded the public key to the security credentials of his IAM user.

However, he still cannot git clone any repositories using SSH.

Which config file in ~/.ssh/ does he need to create in his Linux machine?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Correct Answer - C.

GIT SSH access is a commonly used method to connect with AWS CodeCommit from a remote server.

Check.

https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-ssh-unixes.html

Option A is incorrect: Because the host should be limited as CodeCommit service rather than the wildcard.

Option B is incorrect: Because since CodeCommit is used in several regions, git-codecommit.ap-south-1.amazonaws.com is incorrect as it is limited in the region of ap-south-1.

Option C is CORRECT: Because this is the correct configuration settings for SSH connection.

Option D is incorrect: Because the value for User should be the SSH key ID that is in the IAM Security Credential tab as below:

Policy ARN —_arn:aws:iamn EEE olicy/CodeDeployDemo-EC2-Permissions (2)

Description

Permissions  Policyusage Policy versions += Access Advisor

Access advisor shows the service permissions granted to this user and when those services were last accessed. You can use this information to revise your policies. Learn more

Note: Recent activity usually appears within 4 hours. Data is stored for a maximum of 365 days, depending when your region began supporting this feature. Learn more

Filter: No filter ~

Service Name + Access by Entities Last Accessed ~

‘Amazon $3 s8-admin-access and 1 more 101 days ago

Showing 1 results

To connect with AWS CodeCommit using SSH, the new employee needs to create a configuration file in his Linux machine, in the .ssh directory. This file is used by the SSH client to identify the correct private key to use when connecting to a CodeCommit repository.

In this case, the employee has already created a key pair using ssh-keygen and uploaded the public key to the security credentials of his IAM user in AWS. So, the employee needs to create a configuration file with the following format:

javascript
Host git-codecommit.<region>.amazonaws.com User <IAM user ID> IdentityFile ~/.ssh/<private key file name>

The <region> value in the Host line should be replaced with the AWS region where the CodeCommit repository is located. For example, if the repository is in the ap-south-1 region, the Host line should be Host git-codecommit.ap-south-1.amazonaws.com.

The <IAM user ID> value in the User line should be replaced with the IAM user ID of the employee.

The <private key file name> value in the IdentityFile line should be replaced with the name of the private key file that was created earlier using ssh-keygen. By default, this file is named id_rsa.

With this in mind, let's take a look at the provided answer options:

A. Host * User IAMUSREIDEXAMPLE IdentityFile ~/.ssh/id_rsa

This option uses a wildcard Host value, which means it will match any SSH connection attempts. This is not recommended for security reasons. Additionally, the User value is incorrect and should be replaced with the employee's IAM user ID. Finally, the IdentityFile value is incorrect and should include the name of the private key file.

B. Host git-codecommit.ap-south-1.amazonaws.com User APKAXXXXXXXXXEXAMPLE IdentityFile ~/.ssh/id_rsa

This option uses the correct Host value, with the AWS region included. The User value is incorrect and should be replaced with the employee's IAM user ID. The IdentityFile value is correct and includes the name of the private key file.

C. Host git-codecommit.*.amazonaws.com User APKAXXXXXXXXXEXAMPLE IdentityFile ~/.ssh/id_rsa

This option uses a wildcard Host value, which means it will match any CodeCommit repository in any AWS region. This is not recommended for security reasons. Additionally, the User value is incorrect and should be replaced with the employee's IAM user ID. The IdentityFile value is correct and includes the name of the private key file.

D. Host git-codecommit.*.amazonaws.com User IAMUSREIDEXAMPLE IdentityFile ~/.ssh/id_rsa.pub.

This option uses a wildcard Host value, which means it will match any CodeCommit repository in any AWS region. This is not recommended for security reasons. Additionally, the User value is incorrect and should be replaced with the employee's IAM user ID. The IdentityFile value is incorrect and should include the name of the private key file, not the public key file.

Therefore, the correct answer is B.

Note that if the employee needs to connect to CodeCommit repositories in multiple AWS regions, he will need to add a separate Host block for each region, with the correct AWS region value in each Host line.