Use ssh in Git.
STEP1
First of all, check if you have had public key by:
cd ~/.ssh
ls
If you have foo and foo.pub, it means that you aleardy have a private key and a public key. Repeat the following methods will overwritten the keys if they have the same name.
To generate ssh key, use the command below:
ssh-keygen -t rsa -C "your_email@youremail.com"
Feel free to enter ENTER during the generation.
However, if you are generating another ssh key, you may want to set a different name for it in the first step.
STEP2
To check your public key (Note, id_rsa is the default name):
cat ~/.ssh/id_rsa.pub
Copy it and paste into GitHub's settings page in Account Settings->SSH Keys->Add SSH key.
Note: if you use this key to access to your remote server, then you can copy the content of your public key and paste it into the ~/.ssh/authorized_keys file.
STEP3
To test it:
ssh -T git@github.com
NOTE
If you want to generate another ssh key with different account at the same time, you can first generate another ssh key named other_rsa
.
Then add those by using:
$ ssh-add ~/.ssh/id_rsa
$ ssh-add ~/.ssh/other_rsa
Finally, add a file named config
in the ~/.ssh folder and append those content:
host github // alias
Hostname github.com
User git
IdentityFile ~/.ssh/id_rsa
host gitlab // alias
Hostname gitlab.com
User git
IdentityFile ~/.ssh/other_rsa
Subscribe to JuniperPhoton's Blog
Get the latest posts delivered right to your inbox