1

I want to switch between two different github accounts on my mac. For example, I am currently using my personal MAC and I have set up my personal github account on this MAC. But at home I have to do some office work and want to use the office github account. I want to ask few questions.

  • How I can switch between different github accounts?
  • I want to set up SSH key for my office account but I already have the SSHkey setup for github for my personal account so how can I set up to my office github account and back?

Actually, I want to create a new repository for my office account but when I am using terminal it is synced with my personal account. So how to get rid or switch between two account?

anna
  • 585
  • 1
  • 6
  • 22
Madu
  • 4,849
  • 9
  • 44
  • 78

1 Answers1

0

Based on your question assuming you've 1 or more workstations(laptops & PCs) and you want to have multiple public ssh keys. Please follow these steps.

Step 1: Open your command prompt.

Step 2: Check your available ssh keys, first

  home@name:~$ $ ls -al ~/.ssh

You'll see some files if you've Example: id_pra.pub id_prab.pub id_rsa

Step 3: Generate a new SSH key with an email as a provider Generate a new SSH key, copy and paste the text below, making sure to substitute in your email address. The default settings are preferred, so when you're prompted to "Enter a file in which to save the key", just press Enter to continue.

  home@name:~$  ssh-keygen -t rsa -C "your-email@example.com"

    Generating public/private rsa key pair.
     Enter file in which to save the key (/home/you/.ssh/id_rsa):

Now, you'll be asked to enter a passphrase or strong password

    Enter passphrase (empty for no passphrase): [Type a passphrase]
  # Enter same passphrase again: [Type passphrase again]

If the password matches you'll see something like this.

 Your identification has been saved in /home/you/.ssh/id_rsa.
 # Your public key has been saved in /home/you/.ssh/id_rsa.pub.
 # The key fingerprint is:
 # 01:1f:f5:3d:cb:82:d3:19:a1:7f:f1:58:4d:f2:a1:db your-email@example.com

Now add your new key to the ssh-agent:

 home@name:~$ eval "$(ssh-agent -s)"
  Agent pid 63675
 home@name:~$  ssh-add ~/.ssh/id_rsa

Step 4: Next Add your SSH key to your account(Github/bitbucket)

Run the following commands to copy the key to your clipboard. Keep in mind that your key may also be named id_dsa.pub, id_ecdsa.pub or id_ed25519.pub.

  home@name:~$  sudo apt-get install xclip
 # Downloads and installs xclip. If you don't have `apt-get`, you might
  need to use another installer (like `yum`)

 home@name:~$ xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

Another way of doing this is open the .ssh directory in your text editor and copy the code from your ssh key file. Example file name id_rsa.pub Now login to your Github and click on account settings, and then SSH keys, then click on Add key button and paste the code and give it a title(may be your pc or laptop name).

Step 5: To make sure everything is working, you'll now try SSHing to GitHub. When you do this, you will be asked to authenticate this action using your password, which was the passphrase you created earlier.

Open your terminal and type this

   home@name:~$  ssh -T git@github.com
   # Attempts to ssh to GitHub

It's possible that you'll see this error message:

    The authenticity of host 'github.com (207.97.227.239)' can't be established.  
    # RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
    # Are you sure you want to continue connecting (yes/no)?

Finally you'll see this message if everything is correctly configured.

  Hi username! You've successfully authenticated, but GitHub does not
  # provide shell access.

You're done!.

Prabhakar
  • 6,458
  • 2
  • 40
  • 51