Let's try to clone the HelloWorld repository from CodeCommit to our development machine; but before that, we have to establish SSH authentication. To do that, we have to perform the following operations to generate the SSH keys:
awsstar@awsstar:~$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/awsstar/.ssh/id_rsa): Created directory '/home/awsstar/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/awsstar/.ssh/id_rsa. Your public key has been saved in /home/awsstar/.ssh/id_rsa.pub. The key fingerprint is: SHA256:NMUiRSDRD9SxrSIcYm9A4BYau2TOaeEfk5TgRmy3i4o root@aa21529d724f The key's randomart image is: +---[RSA 2048]----+ |+=. o+o=+o. | |=*o...+ o+. | |+O=oo ++.. | |Oo+*.. ..o | |.*.+* . S | |...oo. . | |o . | |E | | | +----[SHA256]-----+
The preceding command will create two keys; one is the public key (id_rsa.pub) and the other one is the private key (id_rsa).
Now, we have to upload the public key to the user of AWS we created:
awsstar@awsstar:~$ cd .ssh awsstar@awsstar:~/.ssh$ aws iam upload-ssh-public-key --user-name awsccuser --ssh-public-key-body "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCk437p8/JmhGOdM9oYNK/r1xpOnuA2cQNfYys7lnE9gXJdTEjniHNFcJZMkIVmtYQGAqEh37BWGfXl4s5iw/NSfkDuZf8zegAgyPryR0KTTUG2f/rrtyLtlAPlSXjtCmHakZzhwIoRJtzkDbSpKoUOD8fNnS3kKIwk7Dp3+gGLLgo9eoZdud9h/E5+NpORog7wg7xaTgg3mwa9StaPHKMxJNwNc71dIuUyAh2S6bDbHB3QWLNfrJABYqPq5HGFh3KLogH9GHBMajshLEOS4Ygk3uC8FzB+eP4oneuWd2n68N3qg5RmX0U5lAL8s3+ppuhmjlbSvDOdBUJdpgEL/AQZ awsstar@awsstar"
We need to make a note of some details, such as the SSHPublicKeyId provided as output in thew JSON format, while uploading the SSH public key.
We have to bring about some modification in the config file lying in $HOME/.ssh/config:
awsstar@awsstar:~$ vi .ssh/config Host git-codecommit.us-east-1.amazonaws.com User APKAIGJDPRJL3INHSJ6Q IdentityFile ~/.ssh/id_rsa
Once we are done saving the config file, let's see the connectivity between the development machine and AWS CodeCommit:
awsstar@awsstar:~$ ssh git-codecommit.us-east-1.amazonaws.com The authenticity of host 'git-codecommit.us-east-1.amazonaws.com (54.239.20.155)' can't be established. RSA key fingerprint is SHA256:eLMY1j0DKA4uvDZcl/KgtIayZANwX6t8+8isPtotBoY. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'git-codecommit.us-east- 1.amazonaws.com,54.239.20.155' (RSA) to the list of known hosts. You have successfully authenticated over SSH. You can use Git to interact with AWS CodeCommit. Interactive shells are not supported.Connection to git-codecommit.us-east-1.amazonaws.com closed by remote host. Connection to git-codecommit.us-east-1.amazonaws.com closed.
We get the output that says Successfully authenticated over SSH, so now we are ready to clone the repository. We can clone the SSH URL of the repository, which we obtain from the JSON output while creating the repository:
awsstar@awsstar:~$ git clone ssh://git-codecommit.us-east- 1.amazonaws.com/v1/repos/HelloWorld Cloning into 'HelloWorld'... warning: You appear to have cloned an empty repository. checking connectivity... done awsstar@awsstar:~$ ls HelloWorld awsstar@awsstar:~$
So, we cloned an empty repository; now it's time to put a sample index.html file in the CodeCommit HelloWorld repository: