Skip to content

Instantly share code, notes, and snippets.

@DennisGentry-Zoetis
Created December 3, 2022 05:21
Show Gist options
  • Save DennisGentry-Zoetis/6530c75d9dcd7a5144623b1f4a366135 to your computer and use it in GitHub Desktop.
Save DennisGentry-Zoetis/6530c75d9dcd7a5144623b1f4a366135 to your computer and use it in GitHub Desktop.
If an ssh server is rejecting your keys, run this on the server
#!/usr/bin/env bash
chown -R $USER ~/.ssh
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chmod 600 ~/.ssh/config
# This unnecessarily closes permissions on .pub keys too, but whatever
chmod 600 ~/.ssh/id_*
@DennisGentry-Zoetis
Copy link
Author

You can debug a bit about what's going on with an ssh attempt using -v as in ssh -v [email protected], but it can still be difficult to tell why a remote server is rejecting your key. Usually you need to enable debugging from the ssh server to see what's going on, but also usually, the problem is that the ssh server is unhappy about some aspect of the permissions or ownership of one of the above-listed files. The above commands will make the problem not be permissions of your .ssh directory, config file, or authorized_keys file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment