A comprehensive guide on how to clone organization-owned private repositories on AWS EC2 instances using deploy keys. This method is secure and doesn’t require storing personal access tokens on the server.
ssh-keygen -t ed25519 -a 100 -C "your-github-email@example.com"Note
Replace
your-github-email@example.comwith your actual GitHub account email
/home/ec2-user/.ssh or /home/ubuntu/.ssh)cat ~/.ssh/id_ed25519.pubCopy this public key - you’ll need it for the next step.
Warning
Do not modify the public key content when pasting it into GitHub
Verify that your EC2 instance can authenticate with GitHub:
ssh -T git@github.comYou might see a confirmation prompt:
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Type yes to proceed.
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
Hi YourORG/YourRepo! You've successfully authenticated, but GitHub does not provide shell access.
Update package manager and install Git:
# For Amazon Linux/CentOS/RHEL
sudo yum update
sudo yum install git
# For Ubuntu/Debian
sudo apt update
sudo apt install gitNow you can clone your private repository using SSH:
git clone git@github.com:OrgName/your-repo.gitReplace OrgName/your-repo.git with your actual organization and repository name.
or just
For detailed debugging information:
ssh -vT git@github.comTip
This method is preferred over using personal access tokens as it provides repository-specific access and doesn’t expose your personal GitHub credentials.