4 KiB
Setting multiple accounts
Source: https://betterprogramming.pub/how-to-use-multiple-github-accounts-with-one-computer-c9ba3f851b75
For windows I use
ssh-keygen -t rsa -C “your-email-address”
- t stands for ‘type’ and rsa is type of encryption
- C is for comment
- The following will then show:
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/your_username/.ssh/id_rsa):
Copy and paste the path followed by an identifiable name for the file:
/c/Users/your_username/.ssh/id_rsa_IDENTIFIABLE_NAME_HERE
I named my one test for the sake of this tutorial:
/c/Users/your_username/.ssh/id_rsa_test
Make sure you don’t override id_rsa as this is your existing key for your original account.
It will then ask you for the following:
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Press ‘Enter’ twice to leave it blank.
You can now type in the following command to see all the SSH keys you have on your local machine:
ls -al ~/.ssh
- ls lists all the files in the current directory
- a is for listing all files including hidden ones
- l is for listing in a long format
You should then get something similar to this:
total 46
drwxr-xr-x 1 your_username 1049089 0 Jan 26 10:40 .
drwxr-xr-x 1 your_username 1049089 0 Jan 23 12:12 ..
-rw-r--r-- 1 your_username 1049089 3326 Nov 30 11:21 id_rsa
-rw-r--r-- 1 your_username 1049089 748 Nov 30 11:21 id_rsa.pub
-rw-r--r-- 1 your_username 1049089 1675 Jan 26 10:40 id_rsa_test
-rw-r--r-- 1 your_username 1049089 399 Jan 26 10:40 id_rsa_test.pub
-rw-r--r-- 1 your_username 1049089 803 Nov 30 12:08 known_hosts
You should be able to see your new SSH key file. As you can see in my one I have both id_rsa_test and id_rsa_test.pub.
id_rsa_test is your private key stored on your machine, whilst id_rsa_test.pub is the public key which you will provide GitHub with.
Next you need to copy the SSH key which is stored in id_rsa_test.pub file. You can open this in text editor of your choice. I am currently using atom so I opened the file using the following command:
atom ~/.ssh/id_rsa_test.pub
You will then get something similar to this:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDEmSbc7ms4SNIf7G0e9EqdrQRTB17VFTqRtCbQ55sSc11xZP5B07UXf9+................a955cf1GUzsNIr60E7VuVxirrr+K2WcleqifnDEg1H/VbyJtEekh4Aav9csBwemTz3test@test.com
The key is actually longer but I shortened it for the sake of this tutorial.
Copy this and navigate to your GitHub account → Settings → SSH and GPG keys
Click on New SSH key
Give your new key a title and then paste the new generated SSH key you copied before. It is a good idea to name your keys after the machine they’re from. As you can see I have three, Macbook, Windows and Cloud9 IDE.
If you’re on a Mac you should be able to add this key on your terminal as well using the command below:
ssh-add ~/.ssh/id_rsa_test
For enabling ssh:
39
In Windows PowerShell (run as admin):
-
Check the current status of ssh-agent:
Get-Service | ?{$_.Name -like '*ssh-agent*'} | select -Property Name, StartType, Status -
Enable the Service if it is disabled:
Set-Service -Name ssh-agent -StartupType Manual -
Start the Service:
Start-Service ssh-agentthen
cd ~ -
Add your key as before:
ssh-add <path to the key>
Creating config file : format
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work

