Logo

dev-resources.site

for different kinds of informations.

Push to multiple GitHub accounts!

Published at
12/28/2024
Categories
webdev
github
vscode
ssh
Author
nikhil_mahato
Categories
4 categories in total
webdev
open
github
open
vscode
open
ssh
open
Author
13 person written this
nikhil_mahato
open
Push to multiple GitHub accounts!

Generate SSH Key

For each account, generate a separate SSH key:

ssh-keygen -t ed25519 -C "your-email-for-first-account" -f ~/.ssh/id_ed25519_first
ssh-keygen -t ed25519 -C "your-email-for-second-account" -f ~/.ssh/id_ed25519_second

Enter fullscreen mode Exit fullscreen mode
  • -t ed25519: Specifies the type of key (ed25519).
  • -C "your-email-for-first-account": Adds a comment for identification.
  • -f ~/.ssh/id_ed25519_first: Specifies the file name for the private key (~/.ssh/id_ed25519_first) and the public key will automatically be named ~/.ssh/id_ed25519_first.pub.

Add SSH Keys to the Agent

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_first
ssh-add ~/.ssh/id_ed25519_second

Enter fullscreen mode Exit fullscreen mode

List Existing SSH Keys

Run the following command to list your SSH keys:

ls ~/.ssh

Enter fullscreen mode Exit fullscreen mode

You should see files like id_ed25519, id_ed25519.pub, id_ed25519_first, id_ed25519_second, or similar. The .pub files are the public keys.

Add the Public Keys to GitHub

Copy each public key to GitHub:

cat ~/.ssh/id_ed25519_first.pub
cat ~/.ssh/id_ed25519_second.pub

Enter fullscreen mode Exit fullscreen mode

Add these keys to the respective GitHub accounts under Settings > SSH and GPG keys.

Configure ~/.ssh/config

Create or edit the ~/.ssh/config file to define host aliases:

nano ~/.ssh/config

Enter fullscreen mode Exit fullscreen mode

Add the following lines:

Host github-first
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_first

Host github-second
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_second

Enter fullscreen mode Exit fullscreen mode

Save the file.

Test SSH Keys

Use the following command to test your SSH keys with GitHub.
For the first account:

ssh -T git@github-first

Enter fullscreen mode Exit fullscreen mode

You should see a message like:

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

Enter fullscreen mode Exit fullscreen mode

Check for the second account too!
If you encounter any issues, ensure:

  • The correct SSH keys are added to the agent.
  • The ~/.ssh/config file is correctly set up.

Clone Repositories

Use the alias for the desired account:

git clone git@github-first:username/repository.git
git clone git@github-second:username/repository.git

Enter fullscreen mode Exit fullscreen mode

Update an Existing Repository's Remote

If you're switching remotes:

git remote set-url origin git@github-first:username/repository.git
git remote set-url origin git@github-second:username/repository.git

Enter fullscreen mode Exit fullscreen mode

Push Code from VS Code(or any code editor)

1. Open the repository folder in VS Code.

2. Ensure the correct remote is set:

git remote -v

Enter fullscreen mode Exit fullscreen mode

3. Commit and push code:

git add .
git commit -m "Your commit message"
git push origin main

Enter fullscreen mode Exit fullscreen mode
ssh Article's
30 articles in total
Favicon
How to Set Up Key-Based and Password-Based SSH for a Newly Created User on an EC2 Instance
Favicon
SSH Keys | Change the label of the public key
Favicon
่ฎฉๅฎ‰ๅ“ๆ‰‹ๆœบไธๅ†ๅƒ็ฐ๏ผšๅœจๅฎ‰ๅ“ๆ‰‹ๆœบไธŠๆญๅปบ Rust ๅผ€ๅ‘็Žฏๅขƒ
Favicon
SSH port forwarding from within code
Favicon
Mastering Ansible on macOS A Step by Step Guide
Favicon
kkTerminal โ€”โ€” A terminal for Web SSH connection
Favicon
Set Up SSH in 1 Minute Setup Like a Pro (With Some Fun Along the Way)
Favicon
How to Configure GitHub Authentication Using SSH Certificates
Favicon
Understanding SSH: Secure Shell Protocol
Favicon
Check gitlab ssh key auth
Favicon
How I Secured Port 22
Favicon
SSH port forwarding from within Raku code
Favicon
Changing an established SSH connection without disconnecting
Favicon
SSH port forwarding from within Rust code
Favicon
Configure SSH Passwordless Login from Windows to Linux
Favicon
Push to multiple GitHub accounts!
Favicon
Access to Google Cloud Virtual Machine through SSH
Favicon
Large file transfer from VPS to local machine
Favicon
Secure Your Ubuntu VPS: Restrict SSH Access to a Specific IP
Favicon
Accessing Remote Databases Without VPN Using SSH Tunnels
Favicon
Carla Simulator 1 : How to Set Up CARLA Simulator ๐ŸŽ๏ธ๐Ÿ”ฅ
Favicon
Getting Started with Oysape: Exploring Task and Pipeline
Favicon
Increase Debian based Linux VPS serverโ€™s security
Favicon
Splunk - SSH Dashboard Creation
Favicon
Debugging SSH connections: A Comprehensive Guide
Favicon
Understanding SSH Key Pairs: A Developer's Guide
Favicon
SSH Config File - Forgotten Gem
Favicon
SSH kalitini Github.com'ga qo'shish
Favicon
Using SSH to Connect Local Git to Remote Repositories
Favicon
Quickly and Easily Manage Multiple SSH and GPG Keys Across Git Repositories

Featured ones: