{"id":16980125,"url":"https://github.com/peter-bread/git-ssh-management","last_synced_at":"2026-05-03T15:35:53.347Z","repository":{"id":220820910,"uuid":"716340336","full_name":"peter-bread/git-ssh-management","owner":"peter-bread","description":"How to manage multiple GitHub accounts with ssh on one machine.","archived":false,"fork":false,"pushed_at":"2024-02-10T23:26:49.000Z","size":44,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-05T20:56:44.765Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peter-bread.png","metadata":{"files":{"readme":"README.md","changelog":"change.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-08T23:44:56.000Z","updated_at":"2024-01-24T12:48:22.000Z","dependencies_parsed_at":"2024-11-28T07:06:15.798Z","dependency_job_id":"ba280fd4-8254-4f02-8f5b-e4832693d591","html_url":"https://github.com/peter-bread/git-ssh-management","commit_stats":null,"previous_names":["peter-bread/git-ssh-management"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/peter-bread/git-ssh-management","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-bread%2Fgit-ssh-management","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-bread%2Fgit-ssh-management/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-bread%2Fgit-ssh-management/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-bread%2Fgit-ssh-management/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peter-bread","download_url":"https://codeload.github.com/peter-bread/git-ssh-management/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-bread%2Fgit-ssh-management/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32575113,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T06:36:36.687Z","status":"ssl_error","status_checked_at":"2026-05-03T06:36:09.306Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T01:49:33.455Z","updated_at":"2026-05-03T15:35:53.318Z","avatar_url":"https://github.com/peter-bread.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# git ssh management \u003c!-- omit in toc --\u003e\n\n***I am currently working on a [CLI tool](https://github.com/peter-bread/gamon) to manage this along with some additonal functionality.***\n\nAs of right now, this tool depends on the file structure detailed here being implented manually.\n\nIn the future, I hope to make generating this file structure automatic.\n\nIn the even further future, I hope to make this file structure more flexible, but that is not my priority at the moment.\n\n---\n\nHow to manage multiple GitHub accounts with ssh on one machine.\n\n\u003e **Note:** This is an updated solution.\n\u003e\n\u003e [Click here](./README.old.md) to see old solution.\n\u003e\n\u003e [Click here](./change.md) to see explanation of differences and reasons between the two versions.\n\n## Table of Contents \u003c!-- omit in toc --\u003e\n\n- [Prerequisites](#prerequisites)\n- [Our Accounts](#our-accounts)\n- [Set up File Structure](#set-up-file-structure)\n- [Generate ssh keys](#generate-ssh-keys)\n- [Add Stuff to `.gitconfig` Files](#add-stuff-to-gitconfig-files)\n- [gh](#gh)\n\n## Prerequisites\n\nBefore you begin, ensure you have met the following requirements:\n\n- You have installed the latest version of [Git](https://git-scm.com/downloads).\n- You have a Linux or MacOS machine. Windows users can use WSL.\n- You have read the [guide on how to set up multiple accounts with GitHub CLI](./gh-cli.md).\n\n## Our Accounts\n\nIn this let's assume we have two GitHub accounts, *personal* and *work*.\n\nSuppose our emails are:\n\n```text\npersonal: personal@email.com\nwork    : work@org.com\n```\n\n## Set up File Structure\n\nWe will have a directory for each account:\n\n```text\n~/\n    |–– .gitconfig\n    |–– repos/\n    |   |–– personal/\n    |   |   |–– .gitconfig\n    |   |–– work/\n    |   |   |–– .gitconfig\n```\n\nRepos on our personal GitHub will be stored in `~/repos/personal/`.\n\nRepos on our work GitHub will be stored in `~/repos/work/`.\n\n\u003e On Linux: `~/` is the same as `/home/username/`.\n\u003e\n\u003e On MacOS: `~/` is the same as `/Users/username/`.\n\nTo be clear:\n\n\u003e You will only be able to clone repositories with **ssh** when in `~/repos/personal` or `~/repos/work`. These should be repositories **owned by you**.\n\u003e\n\u003e ---\n\u003e\n\u003e If you want to build an app from source, for example, you can clone a public repository **owned by anyone** anywhere you like as long as you use **https**.\n\u003e\n\u003e If you have any other ssh key loaded in your ssh agent or with a default name (like `id_ed25519`), ssh may work for this, but I haven't tested it.\n\n## Generate ssh keys\n\n```bash\nssh-keygen -t ed25519 -C \"personal@email.com\" -f ~/.ssh/github-personal\n\nssh-keygen -t ed25519 -C \"work@org.com\" -f ~/.ssh/github-work\n```\n\n\u003e **Note:** keygen options:\n\u003e\n\u003e - the `-t` lets us specify the key type to be generated. (ed25519 is newer and more secure than the more common rsa key.)\n\u003e\n\u003e - the `-C` option lets us add a comment to the key so it is easier to keep track of.\n\u003e\n\u003e - the `-f` option lets us specify the name of the key and where we want to it be saved.\n\nOur ssh directory will look like:\n\n```text\n~/\n    |–– .ssh/\n        |–– github-personal\n        |–– github-personal.pub\n        |–– github-work\n        |–– github-work.pub\n```\n\n\u003e **Note:** With this management technique we will not be using `~/.ssh/config` (for github at least, we can still use `~/.ssh/config` for other things, e.g. ssh remote connections).\n\n## Add Stuff to `.gitconfig` Files\n\n### `~/.gitconfig` \u003c!-- omit in toc --\u003e\n\n```bash\n# ~/.gitconfig\n\n[user]\n    name = John Smith\n\n[init]\n    defaultBranch = main\n\n[includeIf \"gitdir:~/repos/personal/\"]\n    path = ~/repos/personal/.gitconfig\n\n[includeIf \"gitdir:~/repos/work/\"]\n    path = ~/repos/work/.gitconfig\n```\n\n### `~/repos/personal/.gitconfig` \u003c!-- omit in toc --\u003e\n\n```bash\n# ~/repos/personal/.gitconfig\n\n[user]\n    email = personal@email.com\n\n[core]\n    sshCommand = ssh -i ~/.ssh/github-personal -F /dev/null\n```\n\n### `~/repos/work/.gitconfig` \u003c!-- omit in toc --\u003e\n\n```bash\n# ~/repos/work/.gitconfig\n\n[user]\n    email = work@org.com\n\n[core]\n    sshCommand = ssh -i ~/.ssh/github-work -F /dev/null\n```\n\n## `core.sshCommand` Explanation \u003c!-- omit in toc --\u003e\n\n**`[core]`:** This is a section in the Git configuration that is used for core settings that apply to the entire repository.\n\n**`sshCommand`:** This is an option within the [core] section that allows you to specify a custom SSH command.\n\n**`ssh -i /path/to/personal/key -F /dev/null`:** This is the custom SSH command itself. Let's break it down:\n\n\u003e **`ssh`:** The base SSH command.\n\u003e\n\u003e **`-i /path/to/personal/key`:** Specifies the path to the private key that Git should use when connecting via SSH. In this case, it points to a specific private key file associated with your personal account.\n\u003e\n\u003e **`-F /dev/null`:** Specifies the configuration file to use for SSH. `/dev/null` is a special file that essentially means \"no configuration.\" This is useful when you want to use a specific key (`-i`) without any additional configuration. It ensures that no SSH configuration file is read, including `~/.ssh/config`, and the key specified with `-i` is used directly.\n\n## gh\n\n[Click here](./gh-cli.md) to see how to set up multiple accounts with GitHub CLI.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeter-bread%2Fgit-ssh-management","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeter-bread%2Fgit-ssh-management","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeter-bread%2Fgit-ssh-management/lists"}