How to clone a private repository in GitHub Action using SSH
What is GitHub Actions?
GitHub Actions help you to automate tasks within your software development life cycle. These are event-driven,that means, you can run a series of commands after a specified event has occurred. For example, every time if someone creates a pull request for a repository, the command will automatically run to executes a software testing script.
Please follow below steps to clone the private repository in Git:
Step 1: Generate SSH key
In first step , you have to open your terminal and run the below command (remember to replace your_email@example.com
with your email address).
After this, please provide ssh key file name and passphrase in it. If you don’t provide it, then it will take default names i.e, id_rsa
and id_rsa.pub
Step 2: Copy public key to the GitHub account setting
In this step, you need to copy the content of *.pub file which is our public key and then paste it in your GitHub account settings (By default the name of public key is id_rsa.pub which will be stored in “~/.ssh/id_rsa.pub”).
Step 3: Test SSH key
Please authenticate user using this command ssh -T git@github.com
, once you successfully connected with your GitHub account. You will be receiving below message.
At this movement you are connected with your GitHub account, now its time to use GitHub Action.
Step 4: Adding private key to your secrets
Now copy the content of id_rsa which is the private key and then paste the content in your repository secrets.
Step 5: Setup your GitHub Version Workflow
Now you have successfully cloned the private repository of GitHub using ssh in GitHub Action.
I hope this article help you to understand the configuration of ssh in GitHub and if you find any difficulty then feel free to reach out to me.