• About
  • Products
    • PI-HR Solution
      People management solution
    • PI-TMS
      Transport Management System
    • Fleet Management Solution
      Vehicle management features
    • MFS
      Mobile Financing System
    • Selfcare Solution
      Mobile Apps, VAS & Cloud Service etc.
    • M-Market
      e-Commerce Platform
    • PI-Ticketing
      Online ticket platform
    • Viva Pension
      User Management, Employer, Notice etc.
  • Services
  • Blog
  • Bootcamps
    • JavaScript
    • TypeScript
  • GET IN TOUCH

Multiple Git Account Setup (Ubuntu version)

by Rezwanul Haque | Jan 27, 2021 | Git, Programming & Development | 0 comments

ssh-add is a command for adding SSH private keys into the SSH authentication agent for implementing single sign-on with SSH. The agent process is called ssh-agent;

The cool thing about ssh-agent and ssh-add is that they allow the user to use any number of servers, spread across any number of organizations, without having to type in a password whenever moving between servers. This is commonly used by system administrators to move among the machine they administer. It is also widely used in universities and research institutions for accessing computing resources.

More paractical example would be: when anyone shift to new organization and get a new organization email address for the specific organization. He/She might need to create a VCS(version control system) account at github, bitbuckt, gitlab etc. Most Developer already have one personal account on any of the those VCS sites. So to setup this two account on a single machine sometime complex. In this post we will learn how to setup two or more VCS account on a single machine.

The below command will work on Ubuntu and Mac but Windows may not. But In windows, using window subsystem (WSL) will solved below command issue.

Step 1: Create ssh key for different email address

# With Office Email
ssh-keygen -t rsa -b 4096 -C "rezwanul.haque@vivasoftltd.com" -f rezwanul.viva

# With Personal Email
ssh-keygen -t rsa -b 4096 -C "rezwanul.cse@gmail.com" -f rezwanul-haque

add this ssh public keys to respective VCS accounts

Step 2: Create a config file on .ssh file

touch config

sudo vim config

Add this

# Personal account - default config
Host github.com-rezwanul-haque
        HostName github.com
        User git
        IdentityFile ~/.ssh/rezwanul-haque
# Work account - Viva
Host github.com-rezwanul-viva
        HostName github.com
        User git
        IdentityFile ~/.ssh/rezwanul.viva

Step 3: Create common ~/.gitconfig file at home directory

sudo vim ~/.gitconfig

Add this to ~/.gitconfig

# Default account-Personal
[user]
        name = rezwanul-haque
        email = rezwanul.cse@gmail.com
# Professional account-Office
[includeIf "gitdir:~/<office_work_space_path>/"]
        path = ~/<office_work_space_path>/.gitconfig-viva

Step 4: Create organization specific gitconfig to organization workspace folder

# Professional account-organization
[user]
    name = rezwanul-haque-viva
    email = rezwanul.haque@vivasoftltd.com

Step 5: remove ssh keys and entities from the SSH agent

ssh-add -D

Step 6: Add keys and entities

ssh-add rezwanul-haque
ssh-add rezwanul.viva

# Check if added or not
ssh-add -l

Step 7: Test with Connection using ssh

ssh -T github.com-rezwanul-haque
ssh -T github.com-rezwanul-viva

Also read this aricle on my personal gist

Step 8: Cloning any project with organization account(required)

# need to add github-hostname
git clone git@<HostName>:Rezwanul-Haque-Viva/<office_project_repo>.git

Example: git clone git@github.com-rezwanul-viva:Rezwanul-Haque-Viva/<office_project_repo>.git

Recent Post

  • Accelerating PHP Application
  • কন্ডিশন (IF-ELSE) এর পরিবর্তে পলিমরফিজম ও ফ্যাক্টরি প্যাটার্নের ব্যবহার
  • How OOP works in JS (Part 1 – Prototype and Prototype Chaining)
  • লোকাল স্টোরেজ এবং সেশন স্টোরেজ
  • জাভাস্ক্রিপ্ট কুকিজ

Category

  • Data (22)
  • Git (2)
  • Personal (6)
  • Programming & Development (26)
  • Technology (4)

account callback function coding datastructure devops git global scope go goenv golang higher order function hoisting Java javascript js lexical scope linkedlist local scope loop loops multiple pass by reference pass by value programmin programming React ReactJS reverse scope Spring Spring Boot Spring Security string UI Design UX Design vcs version Web App yaml yml গ্লোবাল স্কোপ জাভাস্ক্রিপ্ট রিয়েক্ট লোকাল স্কোপ স্কোপ

Believe us, we create stories with our partners day and night
contact@vivasoftltd.com
+88 017 134 284 32
  • Follow
  • Follow

Our Story

About us
Portfolio
How we work
Why Vivasoft

Resources

Contact us
Blog

Locations

Banani Office
Floor #16, Ahmed Tower, 28, 30, Kemal Ataturk Ave, Banani, Dhaka 1213

© Vivasoft Limited • 2022 • All rights reserved.

Office Time: Monday to Friday 10:00 AM – 7:00 PM GMT +6:00