A collection of scripts and commands useful for "quick-start" setup of a brand-new Macbook Laptop (Apple Silicon preferred)
Why? Suppose you have 2 GitHub accounts. One for personal, another for work.
The best (and only) approach for this scenario is to use SSH with
git
.
Start out by downloading the bootstrap_ssh_for_github.sh
shell script
to set up SSH (and GPG for commit verification) on GitHub:
curl -fsSL https://raw.githubusercontent.com/rnag/Mac-Quickstart/main/scripts/bootstrap_ssh_for_github.sh -o bootstrap_ssh_for_github.sh
Then, open the shell script in a text editor.
open -e bootstrap_ssh_for_github.sh
Replace the following values with your actual GitHub account info:
'Personal|user1|[email protected]'
'Work|user2|[email protected]'
Then, run the script:
/bin/bash bootstrap_ssh_for_github.sh
Watch for user input.
Notes:
- This is a guided script.
- Passwords will be masked.
- Public and private keys will be temporarily copied to your clipboard, to aid in the setup process.
After running script, you still receive
an HTTP 403
error upon git push
.
$ git push
remote: Permission to <user>/<repo>.git denied to <your-user>.
fatal: unable to access 'https://github.com/<user>/<repo>/': The requested URL returned error: 403
You might be currently set up to use HTTPS (instead of SSH) for git
.
Note that insteadOf
in git config does not chain. This SO post (along with its answer) might be helpful.
Add the following lines to your ~/.dotfiles/<Project>-github.gitconfig
file.
Replace
<user>
with your GitHub username.
[url "[email protected]<user>:"]
insteadOf = [email protected]:
insteadOf = https://github.com/
Now, try that again:
git push
After running script, you now receive "Write access to repository not granted" message with git push
.
$ git push
ERROR: Write access to repository not granted.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I'm not entirely certain on the cause, but in my case it turns it out I had extraneous identities on ssh-agent
that I had previously deleted.
I also had too many ssh-agent
processes running, which could have contributed to the issue.
See my answer on SO, for the full steps I ran.
If using Enterprise Cloud, you might need to authorize the SSH key for use with SAML.
Under Settings > SSH and GPG keys on your target GitHub account, find your SSH key and ensure SSO is enabled.
Choose Configure SSO
and Authorize
- see image below.
Next, to be safe I closed most if not all open terminal windows.
Then to kill all running ssh-agent
processes, I ran:
kill $(pgrep ssh-agent)
Just to be safe, restart ssh-agent
if needed:
test -z "$SSH_AUTH_SOCK" && eval "$(ssh-agent -s)"
Now ensure any SSH key(s) are added to the agent:
Note: Replace
<user>
with your GH username.
ssh-add ~/.ssh/id_ed25519_<user>
Run git push
again, and should have no errors.
Also, open a new terminal window to confirm with ssh-add -l
that all your identities are preserved in a new shell session.
Let me know if there are any issues or feedback.
Feel free to reach out via email.
You can also open an issue if there is a feature or suggestion you'd like to see. Contributions are welcome.