In this post, I will show you how to set up SSH access to your private git repos, so you can clone a private repo on any server, all you need is terminal access on your server to generate the SSH key
STEP 1 (Generate ssh key)
on your server terminal run the below command to generate an SSH key file:
ssh-keygen -t ecdsa -b 521 -C "[email protected]"
The above command will output
Generating public/private ecdsa key pair.
Enter file in which to save the key (/home/benny/.ssh/id_ecdsa):
git uses /.ssh/id_rsa as the default ssh key path, so enter the path, you can as well change your git default SSH key path
Enter file in which to save the key (/home/benny/.ssh/id_ecdsa):/home/benny/.ssh/id_rsa
When you are prompted to type a passphrase, press Enter.
Enter passphrase (empty for no passphrase):
you can leave the passphrase empty if you want to require a password when pulling changes from the git, then set the password
Your ssh pub key will be generated, copy the pub key using cat
Your public key has been saved in /home/benny/.ssh/id_rsa.pub
cat /home/benny/.ssh/id_rsa.pub
# Then select and copy the contents of the id_rsa.pub file
# displayed in the terminal to your clipboard
STEP 2(Adding a new SSH key to your account)
you can add this SSH key to your github account if you want to have access to all the private repo on your account, you can as well add to a particular private repo
Adding ssh key to your github account
Login to your github profile,
In the upper-right corner of any page, click your profile photo, then click Settings
In the “Access” section of the sidebar, click SSH and GPG keys.
Click New SSH key or Add SSH key.
In the “Title” field, add a descriptive label for the new key. For example, if you’re using a personal server, you might call this key “Personal Server”.
Select the type of key, either authentication or signing (for the purpose of this setup select authentication).
Paste your key into the “Key” field.
That’s all, this SSH key will now have access to all your private repo
Comments (1)
Evansays:
31 December 2022 at 00:41It was really helpful. Thank you