I have a public-private key pair at ~/.ssh being used for SSH connection to GitHub.

In order to test if I've setup SSH with GitHub properly, I used ssh -T git@github.com, which works fine.

Also, If I execute the above command as superuser, it works fine.

ssh -T git@github.com

However, when I use sudo, the command isn't working. I suspect it's not able to access the key pair stored at ~/.ssh when run with sudo

The command below fails.

sudo ssh -T git@github.com

You can easily replicate the issue with any Ubuntu distribution and this GitHub help page.

Edit :

I understand that I can pass the private key to ssh as follows:

ssh -i <path-to-private-key> -T git@github.com

I'm just wondering why using sudo ssh -T git@github.com makes the private key inaccessible.


You can pass the path to your identity file with the -i option to ssh.

ssh user@host -i /path/to/keyfile
  • Yes, this works. I'm just wondering why using sudo makes the private key inaccessible. Oct 14 '15 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.