Access git repository using private keys
Posted By Mohit Shakya | 31-Dec-2017
We'll learn today how to access git ssh repository protocol using private keys.
So following is the step by step process to use ssh protocol for git.
-> first create an SSH key. (Generate SSH/GPG Keys)
using following steps:
$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/sysAdmin/.ssh/id_rsa): /home/sysAdmin/gitPVT Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/sysAdmin/gitPVT. Your public key has been saved in /home/sysAdmin/gitPVT.pub. The key fingerprint is: SHA256:Um1kS4ce1vMLeo2wL87Uehn4P6Xz+Hx4PGHPw7ly+Bs firstname.lastname@example.org The key's randomart image is: +---[RSA 2048]----+ | +o. | | =+oo | | .o+. o | | . .o . . | | . S = + . | | . +.+ oo.| | .+.o+E+| | o..=o=OB| | .+o .*XX| +----[SHA256]-----+
-> login to your git account.
-> Go to settings section (there in top right section your profile icon
-> Now go to SSH and GPG keys (using 'Personal Settings' side menu)
-> click 'new SSH key'
-> paste your public file text
-> now you can perform all
GitHub repo I/O operation just by loading key in your terminal.
following are the loading steps:
$ chmod 400 /home/sysAdmin/gitPVT; $ eval "$(ssh-agent -s)"; $ ssh-add /home/sysAdmin/gitPVT;
For instance, after loading keys in your terminal:
let say your repository: email@example.com:myLabs/baseRepo.git
* To clone the repository you'll use the following command:
$ git clone firstname.lastname@example.org:myLabs/baseRepo.git
* To push/pull data
$ git pull (for pull) $ git push (for push)
I hope this blog will be helpful to you.