Set up the `~/.ssh/config` as follows (i.e., make the host names and ssh key files unique for each GitHub account):
```bash
Host github.com-ekmag
HostName github.com
User ekmag
AddKeysToAgent yes
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
Host github.com-toocomputer
HostName github.com
User toocomputer
AddKeysToAgent yes
IdentityFile ~/.ssh/id_ed25519_toocomputer
IdentitiesOnly yes
```
> *Everything is working as expected now. Is there anything in particular I need to do when I clone repos from the respective GitHub accounts in the future?*
When cloning repositories from the respective GitHub accounts in the future, you'll want to ensure that you're using the correct SSH alias based on the GitHub account you're working with. This guarantees that the right SSH key is used and the correct account is accessed.
Here’s a quick rundown of the key things to do when cloning future repositories:
### 1. **Use the Correct SSH Alias in the Clone URL**
When cloning a repository, make sure you specify the correct SSH host alias that you've defined in your `~/.ssh/config` file. This will tell Git to use the appropriate SSH key for that account.
#### For **ekmag**:
```bash
git clone
[email protected]:ekmag/repository.git
```
#### For **haikutear**:
```bash
git clone
[email protected]:toocomputer/repository.git
```
By using the correct alias (`github.com-ekmag` or `github.com-toocomputer`), Git will use the corresponding SSH key for authentication.
### 2. **Ensure You're Cloning from the Right Account**
If you are cloning a repository from **ekmag**, ensure that you are logged into the correct account on GitHub and that the repository exists under that account.
Similarly, for **toocomputer**, ensure you're using the right account's repository and that the SSH URL uses `github.com-account2` as defined in your SSH config.
### 3. **Verify the Remote URL After Cloning**
Once the repository is cloned, you can check the remote URL with:
```bash
git remote -v
```
Ensure that the remote URL points to the correct GitHub account alias (`github.com-ekmag` or `github.com-toocomputer`).
If you notice that the URL points to the default `github.com`, you can always change it manually to the correct account's alias using:
```bash
git remote set-url origin
[email protected]:username/repository.git # For Account 1
```
or
```bash
git remote set-url origin
[email protected]:username/repository.git # For Account 2
```
### 4. **Verify SSH Key Configuration (Optional)**
If you're ever in doubt about which key will be used for a specific repository, you can verify which key is being used by running the following command before interacting with GitHub (e.g., pushing changes):
```bash
ssh -T
[email protected] # For Account 1
```
or
```bash
ssh -T
[email protected] # For Account 2
```
This will help confirm that the correct SSH key is being used for the repository associated with that account.
### 5. **General Workflow for Future Clones**
- If you're working on a project for **ekmag**, always use `github.com-ekmag` in the URL when cloning and pushing.
- If you're working on a project for **haikutear**, use `github.com-haikutear` in the URL.
This small difference in how you clone repositories ensures that Git will automatically use the correct SSH key associated with each GitHub account.
---
### Recap:
1. **Always use the correct SSH alias** (`github.com-ekmag` or `github.com-haikutear`) when cloning a repository.
2. **Check the remote URL** with `git remote -v` after cloning to confirm the correct account is being used.
3. If needed, **manually adjust the remote URL** with `git remote set-url` if the default `github.com` is used.
4. **Verify SSH authentication** if you're unsure which key is being used.
By following this setup, you'll be able to seamlessly work with both accounts without issues. Let me know if you need any more help down the line!