In Dockerfile RUN git config --global url.ssh://git@github.com/.insteadOf https://github.com/ RUN go env -w GOPRIVATE=github.com/{githubusername}/* RUN mkdir ~/.ssh COPY id_rsa.pub /root/.ssh/id_rsa.pub COPY known_hosts /root/.ssh/known_hosts COPY id_rsa /root/.ssh/id_rsa Related Errors: > git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. https://docs.github.com/en/authentication/troubleshooting-ssh/error-permission-denied-publickey `% eval "$(ssh-agent -s)"` Agent pid 50168 `% ssh-add -l -E sha256` The agent has no identities. If we found the above problem, we can try this command (ref: https://stackoverflow.com/questions/26505980/github-permission-denied-ssh-add-agent-has-no-identities). `% ssh-add ~/.ssh/id_rsa` And then, add SSH key into github https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account