Most of the times we need to create multiple ssh keys in our machine and then configure them. To create ssh-key, run following command
ssh-keygen -t rsa -f filename -b 4096-C "your_email@youremail.com"
In macbook / ubuntu you would already have ssh-keygen
lib installed. -t
specified the type of key we want to generate. -f
specifies the file name, -b
specifies the number of bits in the key to create and -C
is actually a comment. When you execute above command it asks you to enter a phrase where you must remember for future. Now you have created new ssh key and you can see there will be 2 new files in .ssh
folder which will be filename.pub
and filename
.
Now once you got the files generated you must configure the rsa key in config. So, run command sudo vi ~/.ssh/config
and it as shown as below
# Work
Host work.github
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_work
# Personal GITHUB
Host personal.github
HostName github.com
User personal_user_name
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_personal
And copy the content from filename.pub and add it in github. So you have loaded you local ssh-key into your github account. Now you can clone / checkout projects of that github account into your local.