Skip to content

Commit cb03e8f

Browse files
authored
Add SSH key file specification instructions
Added instructions for manually specifying the SSH key file when connecting to GitHub, including example SSH command and expected output.
1 parent a93e027 commit cb03e8f

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

content/authentication/troubleshooting-ssh/error-permission-denied-publickey.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,62 @@ You should see this output:
4545

4646
The connection should be made on port 22{% ifversion fpt or ghec %}, unless you're overriding settings to use [SSH over HTTPS](/authentication/troubleshooting-ssh/using-ssh-over-the-https-port){% endif %}.
4747

48+
## Manually specify the SSH key file
49+
50+
If you've created an SSH key file following the [GitHub documentation](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent), chances are it was created with the default filename of `id_ed25519/id_ed25519.pub`, or similar. If, however, you chose to use a non-default filename, then the commands to SSH into GitHub to test the connection will fail. This is because, by default and without any additional configuration, SSH will try to connect using default/standardized filenames. This can be seen in the following debug output below:
51+
52+
```
53+
user@host:~/.ssh $ ssh -vT git@github.com
54+
debug1: OpenSSH_10.0p2 Raspbian-7, OpenSSL 3.5.4 30 Sep 2025
55+
debug1: Reading configuration data /etc/ssh/ssh_config
56+
debug1: Reading configuration data /etc/ssh/ssh_config.d/20-systemd-ssh-proxy.conf
57+
debug1: /etc/ssh/ssh_config line 21: Applying options for *
58+
debug1: Connecting to github.com [140.82.112.3] port 22.
59+
debug1: Connection established.
60+
<----truncated---->
61+
debug1: Will attempt key: /home/your_username/.ssh/id_rsa
62+
debug1: Will attempt key: /home/your_username/.ssh/id_ecdsa
63+
debug1: Will attempt key: /home/your_username/.ssh/id_ecdsa_sk
64+
debug1: Will attempt key: /home/your_username/.ssh/id_ed25519
65+
debug1: Will attempt key: /home/your_username/.ssh/id_ed25519_sk
66+
debug1: Will attempt key: /home/your_username/.ssh/id_xmss
67+
debug1: Trying private key: /home/your_username/.ssh/id_rsa
68+
debug1: Trying private key: /home/your_username/.ssh/id_ecdsa
69+
debug1: Trying private key: /home/your_username/.ssh/id_ecdsa_sk
70+
debug1: Trying private key: /home/your_username/.ssh/id_ed25519
71+
debug1: Trying private key: /home/your_username/.ssh/id_ed25519_sk
72+
debug1: Trying private key: /home/your_username/.ssh/id_xmss
73+
debug1: No more authentication methods to try.
74+
git@github.com: Permission denied (publickey)
75+
```
76+
77+
To resolve this error, modify the test SSH command as follows:
78+
79+
`ssh -vT git@github.com -i <filename>`
80+
81+
Where `filename` is the filename of the *private key*, **not** the public key. Successful output will be shown as follows:
82+
83+
```
84+
user@host:~/.ssh $ ssh -vT git@github.com -i my_key
85+
debug1: OpenSSH_10.0p2 Raspbian-7, OpenSSL 3.5.4 30 Sep 2025
86+
debug1: Reading configuration data /etc/ssh/ssh_config
87+
debug1: Reading configuration data /etc/ssh/ssh_config.d/20-systemd-ssh-proxy.conf
88+
debug1: /etc/ssh/ssh_config line 21: Applying options for *
89+
debug1: Connecting to github.com [140.82.112.3] port 22.
90+
debug1: Connection established.
91+
<-----TRUNCATED----->
92+
debug1: Host 'github.com' is known and matches the ED25519 host key.
93+
debug1: Found key in /home/user/.ssh/known_hosts:1
94+
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
95+
Hi github_user! You've successfully authenticated, but GitHub does not provide shell access.
96+
debug1: channel 0: free: client-session, nchannels 1
97+
Transferred: sent 4024, received 4272 bytes, in 0.1 seconds
98+
Bytes per second: sent 30574.9, received 32459.2
99+
debug1: Exit status 1
100+
```
101+
102+
This command was issued from within the directory where the private and public key files are stored; this is typically `~/.ssh`, but might be different on your system. Be sure to modify the command to include the relative filepath, if applicable.
103+
48104
## Always use the "git" user
49105

50106
All connections, including those for remote URLs, must be made as the "git" user. If you try to connect with your {% data variables.product.github %} username, it will fail:

0 commit comments

Comments
 (0)