diff --git a/README.md b/README.md index 24a0812..a877842 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ 1. [Generate a new public and private SSH key](https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent) by running: ```zsh - curl https://raw.githubusercontent.com/aboqasem/dotfiles/HEAD/ssh.sh | sh -s "" + bash <(curl https://raw.githubusercontent.com/aboqasem/dotfiles/HEAD/ssh.bash) "" ``` 2. Clone this repo to `~/dev/dotfiles` with: diff --git a/ssh.bash b/ssh.bash new file mode 100755 index 0000000..357ed9b --- /dev/null +++ b/ssh.bash @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +# better defaults when dealing with bash scripts: https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425 +set -e # immediately exit script on any command error +set -u # treat unset variables as an error +set -o pipefail # exit if any piped command fails +DEBUG=${DEBUG:-} +if [ -n "$DEBUG" ]; then + set -x # print all executed commands to stdout +fi + +EMAIL="${1:?"Usage: $0 "}" + +KEY_TYPE="ed25519" +KEY_NAME="id_$KEY_TYPE" + +echo "Generating a new SSH key for GitHub..." + +# Generating a new SSH key +# https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key +ssh-keygen -t "$KEY_TYPE" -C "$EMAIL" -f ~/.ssh/"$KEY_NAME" + +# Adding your SSH key to the ssh-agent +# https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent +eval "$(ssh-agent -s)" + +{ + echo "Host github.com" + echo " AddKeysToAgent yes" + echo " UseKeychain yes" + echo " IdentityFile ~/.ssh/$KEY_NAME" +} >>~/.ssh/config + +ssh-add -K ~/.ssh/"$KEY_NAME" + +echo "$EMAIL namespaces=\"git\" $(cat ~/.ssh/"$KEY_NAME".pub)" >>~/.ssh/allowed_signers + +# Adding your SSH key to your GitHub account +# https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account +echo "Run 'pbcopy < ~/.ssh/$KEY_NAME.pub' and paste that into GitHub" diff --git a/ssh.sh b/ssh.sh deleted file mode 100644 index 083a7e5..0000000 --- a/ssh.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -echo "Generating a new SSH key for GitHub..." - -# Generating a new SSH key -# https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key -ssh-keygen -t ed25519 -C "$1" -f ~/.ssh/id_ed25519 - -# Adding your SSH key to the ssh-agent -# https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent -eval "$(ssh-agent -s)" - -{ - echo "Host github.com" - echo " AddKeysToAgent yes" - echo " UseKeychain yes" - echo " IdentityFile ~/.ssh/id_ed25519" -} >>~/.ssh/config - -ssh-add -K ~/.ssh/id_ed25519 - -# Adding your SSH key to your GitHub account -# https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account -echo "Run 'pbcopy < ~/.ssh/id_ed25519.pub' and paste that into GitHub" diff --git a/synced/symlink/.gitconfig b/synced/symlink/.gitconfig index d2c1c6a..e491030 100644 --- a/synced/symlink/.gitconfig +++ b/synced/symlink/.gitconfig @@ -2,6 +2,7 @@ name = Mohammad Al Zouabi email = mb.alzouabi@gmail.com + signingkey = ~/.ssh/id_ed25519.pub [alias] @@ -142,9 +143,18 @@ [commit] - # https://help.github.com/articles/signing-commits-using-gpg/ gpgsign = true +[gpg] + + # https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification#ssh-commit-signature-verification + # https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key#telling-git-about-your-ssh-key + format = ssh + +[gpg "ssh"] + + allowedSignersFile = ~/.ssh/allowed_signers + [submodule] # Recurse into submodules for every command that has a --recurse-submodules option (except git clone) @@ -207,3 +217,4 @@ [init] defaultBranch = main +