Skip to content

Instantly share code, notes, and snippets.

@git-hub-tig
Forked from brennanMKE/README.md
Created May 3, 2022 08:52
Show Gist options
  • Save git-hub-tig/f3191af7e3ed8961cc7ccea0d017c194 to your computer and use it in GitHub Desktop.
Save git-hub-tig/f3191af7e3ed8961cc7ccea0d017c194 to your computer and use it in GitHub Desktop.
Create SSH Key on Mac for Xcode

Create SSH Key on Mac for Xcode

The docs for GitHub show a command to create a key with the ed25519 encryption method which is not allowed by Xcode. Even if you are not using the Source Control features in Xcode you will often need to use an account with GitHub when you are consuming Swift packages which are pulled from GitHub.

For SSH keys there are 4 algorithms.

  • 🚨 DSA: This is an older algorithm which is no longer supported and is superceded with more modern algorithms.
  • ⚠️ RSA: This algorithm was an improvement but it is now outdated and a more modern method should be used.
  • 👀 ECDSA: Another improvement which is dependent on your computer's ability to generate random numbers.
  • ✅: Ed25519: The most recommended public-key algorithm today which you should use with GitHub.

(Source)

Instead of the command shown in the docs, use ecdsa which Xcode will accept. It can be done with the command below which will create a new key in a file named id_github using the ed25519 algorithm. Use your own email for this key. If you already have a key you could move it into another folder or delete it as you won't be using it anymore.

ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_github -C "[email protected]"

Using id_github for the name to makes it easier to identify the purpose for this key. Once the key is created run the ssh-agent.

eval "$(ssh-agent -s)"

Add the key to the Keychain with this command.

ssh-add --apple-use-keychain ~/.ssh/id_github

Once your new key is ready follow these steps to use it.

  1. Go to Settings on GitHub then to SSH and GPG keys
  2. Remove any keys you won't be using anymore
  3. Copy the contents of your new public key with this command: pbcopy < ~/.ssh/id_github.pub
  4. Add the new key by pasting it in and use a unique label to identify it
  5. Go to Developer Settings then Personal Access Tokens
  6. Delete any unused tokens
  7. Add a new token with an expiration and copy the token
  8. Open Xcode then Preferences
  9. Go to accounts and remove the GitHub account
  10. Add back a GitHub account with your username and the token that was just copied
  11. Select id_github as the SSH key
  12. See that Xcode accepts the new key and checks it with GitHub
  13. Open the Keychain app and search each keychain for id_github
  14. Remove any old keys which will no longer be valid

Once these steps are completed you will be able to use Xcode with GitHub.


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