Sub topic 11
Testing the connection with ssh -T
This chapter assumes you have already generated an SSH key, loaded it into ssh-agent, and added the public key to your GitHub account. Before you change a remote or push anything, you can check the whole chain with one command.
What the test does
ssh -T [email protected] opens an SSH connection to GitHub, offers your keys, and reports the result. The -T option turns off pseudo-terminal allocation. GitHub does not give you an interactive shell, so a terminal is not needed.
The user name is always git. GitHub identifies you by the key you present, not by the user name.
ssh -T [email protected]The first connection
The first time you connect, SSH does not know GitHub's host key. It shows a fingerprint and asks whether to continue.
The authenticity of host 'github.com (140.82.112.3)' can't be established.
ED25519 key fingerprint is SHA256:...
Are you sure you want to continue connecting (yes/no/[fingerprint])?Compare the fingerprint with the values GitHub publishes in its documentation. If they match, type yes. SSH then saves the host key in ~/.ssh/known_hosts and does not ask again.
Reading the result
A working setup prints this message:
Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.The message means authentication succeeded. The connection closing right afterward is expected.
Check that USERNAME is the account you intended. If you have several GitHub accounts, a wrong name means SSH offered a different key than you expected.
The command can fail in several ways:
| Output | Likely cause |
|---|---|
| `Permission denied (publickey).` | GitHub did not accept any key SSH offered. The key may not be loaded, or the public key may not be on your account. |
| `Host key verification failed.` | The saved host key in `known_hosts` does not match what the server presented. |
| `Connection timed out` | Port 22 may be blocked by your network. |
Seeing what SSH is doing
When the result is unclear, add -v for verbose output. Use -vv or -vvv for more detail.
ssh -vT [email protected]Look for lines like these:
Offering public key: ...shows which key files SSH tried.Server accepts key: ...means GitHub recognized that key.Authenticated to github.comconfirms success.
If SSH offers no keys, check that the key is loaded with ssh-add -l, which lists the keys held by ssh-agent.
ssh-add -lThe output The agent has no identities. means you need to run ssh-add for your key.
Exercise
You run ssh -T [email protected] and see "Hi alice! You've successfully authenticated, but GitHub does not provide shell access." You expected the account alice-work. What does this tell you, and how can you investigate?
Show answer
SSH offered a key that is registered to the account alice, not alice-work. Run ssh -vT [email protected] to see which key files were offered, and check ssh-add -l for loaded keys. Then use a ~/.ssh/config entry with IdentityFile and IdentitiesOnly yes to make SSH offer the correct key.