Put SSH keys in .git to make repos USB-portable
2 days ago
- #ssh
- #git
- #deploy-keys
- Use deploy keys exclusively in repository remotes to avoid pushing changes from the wrong account.
- Previously managed per-account keys manually in .ssh subdirectories, but found it cumbersome and error-prone.
- Adapted a solution from SuperUser to place private keys in the .git directory, leveraging Git's behavior.
- Configure SSH to use the key in .git by running: `git config core.sshCommand "ssh -i .git/id_ed25519"`.
- Keys can be renamed, but the SSH command must be updated to reflect the new filename.
- This setup is self-contained and portable, working across different paths or machines without reconfiguration.
- Example initialization walkthrough provided for setting up a local repository and remote with deploy keys.
- Steps include generating SSH keys in .git, adding the public key as a deploy key on the remote, and setting the remote origin.
- A dummy commit can be used to initialize the repository and set the upstream branch.