Skip to content

Latest commit

 

History

History
221 lines (195 loc) · 6.75 KB

SSH Setup for Business GitHub vs Personal Account.md

File metadata and controls

221 lines (195 loc) · 6.75 KB

SSH Setup for Business GitHub Account

Table of Contents

Commands

git remote set-url

 git remote set-url origin [email protected]:company/POSRetail_Php.git

Step 1: Check SSH Keys on Your Machine

  1. Open your Terminal.
  2. Run the following command to check if there are any SSH keys already on your Mac:
    ls -al ~/.ssh

Step 2: Generate an SSH Key for Your Business Account

  1. Run the following command in Terminal to create a new SSH key:
    ssh-keygen -t ed25519 -C "[email protected]"
  2. When prompted, save the key as:
    /Users/amr.elghadban/.ssh/id_ed25519_business_amr_elghadban_adkatech
  3. Leave the passphrase empty (or add one for security).
  4. Result:
    Your identification has been saved in /Users/amr.elghadban/.ssh/id_ed25519_business_amr_elghadban_adkatech
    Your public key has been saved in /Users/amr.elghadban/.ssh/id_ed25519_business_amr_elghadban_adkatech.pub
    The key fingerprint is: 
    SHA256:4AAAAAAhXXXXXXXXXXDyK+M/L2bbbbSs [email protected]
    

Step 3: Add the SSH Key to Your Business GitHub Account

  1. Copy the new public key to your clipboard:
    pbcopy < ~/.ssh/id_ed25519_business_amr_elghadban_adkatech.pub
  2. Go to your GitHub Business account:
    • Click your profile picture → Settings.
    • Navigate to SSH and GPG keys under Access.
    • Click New SSH key.
  3. Paste the public key into the "Key" field.
    • Give it a meaningful title (e.g., MacBook Pro Business Key).
    • Click Add SSH key.

Step 4: Configure the SSH Config File for Multiple Accounts

  1. Open the SSH config file:
    nano ~/.ssh/config
  2. If the file doesn't exist, create it:
    nano ~/.ssh/config
  3. Add the following configuration:
    # Personal GitHub Account
    Host github.aaakk.us.kg-personal
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_ed25519
    
    # Business GitHub Account
    Host github.aaakk.us.kg-business
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_ed25519_business_amr_elghadban_adkatech
    
  4. Save the file:
    • Press Ctrl + O, then Enter.
    • Press Ctrl + X to exit.
  5. Set correct permissions:
    chmod 600 ~/.ssh/config

Step 5: Test the SSH Configuration

Run the following command to test the SSH connection:

Expected Output:

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

Step 6: Clone the Repository Using the Business SSH Configuration

Use the business SSH alias:

git clone [email protected]:<company>/<reponame>.git

Do not use:

git clone [email protected]:<company>/<reponame>.git

Step 7: Move to the Repository

  1. Decide where to move the repository:
    mv ~/POSRetail_Php /Users/amr.elghadban/Desktop/workspace/project_folder
  2. Verify the move:
    ls /Users/amr.elghadban/Desktop/workspace/project_folder
    You should see the project_folder folder.
  3. Navigate to the new location:
    cd /Users/amr.elghadban/Desktop/workspace/project_folder/repo

Step 8: Confirm Everything Works

  1. Check the Git status:
    git status
  2. Ensure the remote origin is set correctly:
    git remote -v
    Expected Output:
    origin  [email protected]:<company>/<reponame>.git (fetch)
    origin  [email protected]:<company>/<reponame>.git (push)
    

Step 9: Verify the Setup

Ensure everything is working as expected.


Step 10:-Optional-Configure Global Identity and Repository-specific Identity

Global Identity

  • Set the identity for global Git identity:
git config --global user.name "Your Personal Name"
git config --global user.email "[email protected]"
  • Confirm the settings:
git config --global --list

Repository-specific Identity (Business Repo)

  1. Navigate to the repository directory:
    cd /Users/amr.elghadban/Desktop/workspace/project_folder/repo
  2. Set the identity for this repository:
    git config user.name "Amr Ahmed Elghadban"
    git config user.email "[email protected]"
  3. Check the repository-specific configuration:
    git config --list --local

GitHub Contribution Graph can be combined by setting the Noreply Email to be the same in both Your Repository or Globally

Globally

   git config --global user.email "[email protected]"
   git config --global user.name "Amr Angry"  

Repository

  git config user.email "[email protected]"
  git config user.name "Amr Elghadban"

Rewrite Past Commits (Optional)

If previous commits were made with the wrong email, you can rewrite them with the correct noreply email:

Then, force-push the changes:

git filter-branch --env-filter '
if [ "$GIT_COMMITTER_EMAIL" = "[email protected]" ]; then
    export GIT_COMMITTER_EMAIL="[email protected]"
    export GIT_AUTHOR_EMAIL="[email protected]"
fi
' -- --all
 git push --force

(Optional) Use .gitconfig Includes for Easier Setup

Use .gitconfig includes to manage multiple identities more efficiently.