Git: Setting Up
Step-By-Step Initialization Of Account
1. Generate Keys
2. Set Git User Profile
3. Register SSH Public Key With Github
4. Test Git Connection
Generate Keys
ssh-keygen -t rsa -b $key_rsa_length -C $email_address
Note: terms with $
are variables which you can set at a separate file during the generation.
Caveat: While many tutorials indicate you can default the path at ~/.ssh/id_rsa
, it is better to give a specific name ID to ensure you do not corrupt your other keys. SSH keys are used for many other applications other than git, hence, you want your keys to be specific.
Check fingerprint of key:
$ ssh-keygen -lf <path_to_key_file>/<file_key> -E sha256
e.g. $ ssh-keygen -lf ~/.ssh/id_ursa_rsa -E sha256
Set Git User Profile
git config --global user.name $id_git
git config --global user.email $email_address
After setting the profile, the test connection attempt, should fail.
eval $(ssh-agent -s) #start ssh-agent in the backgroundssh-add $key_store$key_id # add private key, i.e. $private_authentication_key_with_path
echo "set_git_user_profile [DONE]"git config --list # list Git settings
ssh -T git@github.com # try connecting to git account
# or `ssh -T git@github.com -i <path_to_key>`
For now, the connection will not work yet. This is because the SSH public key has to be registered with the github account.
Register SSH Public Key With Github
# derive the public key from the private key
ssh-keygen -f ~/.ssh/<key.private.file> -y > ~/.ssh/<key.public.file>.pubcd /Users/<user_id>/.ssh/
cat $key_store$key_id'.pub'
echo $demarcator echo ‘Add this public key to Github account’
Log on to Github and register the public key.
Caveat: Keep the private key safe, and back up the key pairs safely.
Get the generated public key from the file, and copy-paste the contents on the following:
# check the hash of the public key. This should match what is stated in the added key in github
$ ssh-keygen -lf ~/.ssh/<key_file_name>.pub # $key_store$key_id'.pub'
Test Git Connection
# test git log-in
eval $(ssh-agent -s)
ssh-add $key_store$key_id # ssh -i $key_store$key_id git@github.com
ssh -T git@github.com # try connecting to git account# check hash of key
ssh-add -l -E sha256
You should be able to connect now.
Let’s set a user menu to assist for semi-automation:
Github scripts for the tutorial: Chapter_01_Access_Setup
There is no abstract art. You must start with something. — Pablo Picasso
Git
Chapter 01: Setting up account
Chapter 02: Setting up repo, Get and Update
Chapter 03: Collaboration And Update
Chapter 04: Workdesk