Step 1: Create SSH keys
- Open PowerShell on your local machine.
- Run the following command to generate a new SSH key for your first GitHub account:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
- Follow the prompts to specify a file location for the SSH key and set a passphrase (optional).
Step 2: Add SSH keys to the SSH agent
- Start the SSH agent by running the following command in PowerShell:
Start-Service ssh-agent
- Add the private SSH key to the agent by running the following command, replacing
<private_key_path>
with the path to your private SSH key:
ssh-add <private_key_path>
Step 3: Add the public key to your GitHub account
- Copy the contents of the public key file by running the following command in PowerShell:
Get-Content "<public_key_path>"
- Go to your GitHub account settings in your web browser and navigate to "SSH and GPG keys".
- Click on "New SSH key" and paste the copied public key into the "Key" field.
- Give the SSH key a descriptive title and click on "Add SSH key" to add it to your GitHub account.
Step 4: Modify the SSH config file
- In PowerShell, run the following command to create a new SSH config file or open an existing one:
notepad $env:USERPROFILE\\.ssh\\config
- In the text editor, add the following lines, replacing
<alias>
with an alias of your choice, and<github_username>
with your first GitHub account's username:
Host <alias>
HostName github.com
User <github_username>
IdentityFile <private_key_path>
- Save and close the config file.
Step 5: Fork & clone repos
- In PowerShell, navigate to the directory where you want to clone a repository.
- Run the following command to clone a repository from your first GitHub account, replacing
<alias>
with the alias you set in the config file, and<repo_url>
with the URL of the repository you want to clone:
git clone git@<alias>:<github_username>/<repo_url>.git
- You may be prompted to enter the passphrase for your SSH key if you set one during the key generation process.
That's it! You can now work with multiple GitHub accounts using SSH keys and PowerShell. Remember to repeat these steps for each additional GitHub account you want to work with, using a different alias, SSH key, and GitHub username for each account.
Top comments (0)