The interaction between github and local system can be configured using a file called config
inside ~/.ssh/
. Here each host can be given specific setting to act accordingly.
For github host can be defined as Host github.com
. More general setting can be added under Host *
.
Adding keys to the agent is done through AddKeysToAgent yes
.
In Mac OS, it is possible to store even the passphrase to their secure keychain password management system.
With UseKeychain yes
that setting is enabled. In the case of git-lfs
for a push or fetch operation, passphrase must be entered more than once.
Since AddKeysToAgent yes
setting is present, ssh-agent usually looks into ~/.ssh/ directory for the private keys. A private key placed inside a subdirectory will not be looked into unless specified explicitly. This can be done using
Identityfile <privatekeylocation>
. In my case, the private key for github is under github
subdirectory.
So, putting all these together, we get the following...
Host github.com
AddKeysToAgent yes
UseKeychain yes
Identityfile ~/.ssh/id_rsa # or inside another directory ~/.ssh/github/github_ed25519
ssh -T [email protected]
or
ssh -vT [email protected]
If done correctly, we should be greeted with our username.