git configure ssh key code example

Example 1: add ssh key to github

### ADD SSH key to Github  ###

# Check if you have a key?
ssh-add -l

# If not? then follow steps to generate key
ssh-keygen -t rsa -b 4096 -C your__gmail

# Now for copy the key use xclip tool or just goto file and copy
sudo apt install xclip
xclip -sel clip < ~/.ssh/id_rsa.pub

# Now goto github.com and goto settings 
# select  SSH and GPG keys
# New SSH key
# Enter "your__choice__name" in title field...
# Paste your public key into the Key field
# Click Add SSH key

DONE!!!

Example 2: git specify ssh key for repo

# Add this to ~/.ssh/config
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa_github

Example 3: git change ssh key

git config core.sshCommand "ssh -i ~/.ssh/id_rsa_example -F /dev/null"
git pull
git push

# Other way
edit .git/config file like:

[core]
	sshCommand = ssh -i ~/.ssh/id_rsa_example -F /dev/null

Example 4: ssh key for github

SSH stands for Secure Shell.
When working with a GitHub repository,
you'll often need to introduce yourself to
GitHub using your username and password.
SSH key is an alternate way to identify yourself
that doesn't require you to enter you username and password every time.

SSH keys come in pairs, a public key that
gets shared with services like GitHub,
and a private key that is stored only on
your computer. If the keys match, you're granted access.