Add public ssh keys ...
... to allow other people to give me access to their systems
This commit is contained in:
parent
9b4c9fc98b
commit
0fb069f4bc
5 changed files with 127 additions and 0 deletions
|
|
@ -100,6 +100,7 @@ _git config core.sparseCheckout true
|
|||
echo "/*"
|
||||
echo "!LICENSE.txt"
|
||||
echo "!README.md"
|
||||
echo "!.ssh"
|
||||
} > "$DOTFILES_DIR/info/sparse-checkout"
|
||||
|
||||
|
||||
|
|
|
|||
83
.local/bin/ssh-setup
Executable file
83
.local/bin/ssh-setup
Executable file
|
|
@ -0,0 +1,83 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Set up `ssh` on a machine trusted with full access
|
||||
#
|
||||
# Install my public `ssh` keys into ~/.ssh/authorized_keys
|
||||
# taken from the local `dotfiles` repository
|
||||
# => Run `dotfiles pull` first to obtain the latest keys
|
||||
#
|
||||
# See: https://code.webartifex.de/alexander/dotfiles
|
||||
|
||||
set -eu
|
||||
|
||||
|
||||
XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
|
||||
|
||||
DOTFILES_DIR="${DOTFILES_DIR:-$XDG_DATA_HOME/dotfiles}"
|
||||
|
||||
SSH_KEYS_FILE="$HOME/.ssh/authorized_keys"
|
||||
|
||||
|
||||
|
||||
if [ ! -d "$DOTFILES_DIR" ]; then
|
||||
echo "" >&2
|
||||
echo "The dotfiles are not installed at: $DOTFILES_DIR" >&2
|
||||
echo "=> Run dotfiles-install first" >&2
|
||||
echo "" >&2
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
|
||||
_git() {
|
||||
git --git-dir="$DOTFILES_DIR" --work-tree="$HOME" "$@"
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Take my public `ssh` keys out of the local repository
|
||||
|
||||
_keys_path=$(mktemp)
|
||||
trap 'rm -f "$_keys_path"' EXIT
|
||||
|
||||
_git show "HEAD:.ssh/authorized_keys_webartifex" > "$_keys_path"
|
||||
|
||||
|
||||
|
||||
# Show which keys are being authorized
|
||||
|
||||
echo ""
|
||||
echo "Authorizing these keys:"
|
||||
echo ""
|
||||
if command -v ssh-keygen >/dev/null 2>&1; then
|
||||
ssh-keygen -lf "$_keys_path"
|
||||
else
|
||||
cat "$_keys_path"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
|
||||
|
||||
mkdir -p "$HOME/.ssh"
|
||||
|
||||
|
||||
|
||||
# Append only keys that are not already authorized
|
||||
|
||||
touch "$SSH_KEYS_FILE"
|
||||
|
||||
while IFS= read -r _key; do
|
||||
if ! grep -qxF "$_key" "$SSH_KEYS_FILE"; then
|
||||
echo "$_key" >> "$SSH_KEYS_FILE"
|
||||
fi
|
||||
done < "$_keys_path"
|
||||
|
||||
|
||||
|
||||
chmod 700 "$HOME/.ssh"
|
||||
chmod 600 "$SSH_KEYS_FILE"
|
||||
|
||||
|
||||
|
||||
echo "Installed the public keys into: $SSH_KEYS_FILE"
|
||||
25
.ssh/README.md
Normal file
25
.ssh/README.md
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# `ssh`-related Files
|
||||
|
||||
This folder contains
|
||||
my [public SSH keys](./authorized_keys_webartifex),
|
||||
to be enabled locally with [`ssh-setup`](../.local/bin/ssh-setup).
|
||||
|
||||
|
||||
## How the keys are managed
|
||||
|
||||
The keys are tracked as `authorized_keys_webartifex`
|
||||
and deliberately *not* as `~/.ssh/authorized_keys`:
|
||||
|
||||
- The file is sparse-excluded and never checked out into `~/`
|
||||
- [`ssh-setup`](../.local/bin/ssh-setup) reads it
|
||||
straight out of the local repository (i.e., `HEAD`)
|
||||
and appends any missing keys to the untracked `~/.ssh/authorized_keys`
|
||||
- Keys added locally on a machine are never touched:
|
||||
neither `dotfiles pull` nor a re-run of `ssh-setup` removes them
|
||||
- Because the two paths differ,
|
||||
the machine-local file never shows up in `dotfiles status`
|
||||
and cannot be overwritten by any `dotfiles` operation
|
||||
|
||||
So, run `dotfiles pull` and then `ssh-setup`
|
||||
to bring a trusted machine up to date with the latest keys,
|
||||
giving me access to it.
|
||||
6
.ssh/authorized_keys_webartifex
Normal file
6
.ssh/authorized_keys_webartifex
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOhhfx063dGoaE62cbdyGL3kp1AIovWFojQGNdqUpxr8 laplace
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMRDaWrT2hH7BOV4Zv1ctVGqwfeqkssnHklRXBmng6Wr lazarus
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN0GVKtgpgzpdf7E6e2vCytDSa2zPSgZ+8fAKCOotugH peter
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDq2JDk3pX79p7ampZhVQxIZg4qaUBkTPIQSbK0XeKoc wilddog
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGGNCrFt/gUbBHVqhthBuRmdDH6yS30+GGcCnARSzg+q wolfram
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKfaK5LUp7ghZLfl7urwQx+l+m/Vm7iksz8deGx4L5sD workstation2
|
||||
12
README.md
12
README.md
|
|
@ -18,6 +18,18 @@ It targets [Debian](https://www.debian.org/) 13
|
|||
be it end-user software or common development utilities.
|
||||
|
||||
|
||||
## SSH Keys
|
||||
|
||||
If I told you to go here and copy/paste my public `ssh` keys
|
||||
to give me access to one of your servers,
|
||||
find them
|
||||
either [here](.ssh/authorized_keys_webartifex)
|
||||
or [here](https://code.webartifex.de/alexander.keys).
|
||||
|
||||
Read [this](https://code.webartifex.de/alexander/dotfiles/src/branch/main/.ssh#how-the-keys-are-managed)
|
||||
for how the keys are managed.
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
Simply run:
|
||||
|
|
|
|||
Loading…
Reference in a new issue