Skip to content

Instantly share code, notes, and snippets.

@ChlodAlejandro
Last active February 14, 2022 13:11
Show Gist options
  • Save ChlodAlejandro/0cf80eeefd79cf4686626d8d5312afbe to your computer and use it in GitHub Desktop.
Save ChlodAlejandro/0cf80eeefd79cf4686626d8d5312afbe to your computer and use it in GitHub Desktop.
Generate an SSH key, delegate a subdirectory for it, and add it to your SSH agent. Uses ED25519.
#!/bin/bash
echo : Configure
echo
echo -n "Subpath: "
read SSHK_DIR < /dev/tty
echo -n "Comment: "
read SSHK_COM < /dev/tty
echo
if [ -z "$SSHK_DIR" ]
then
echo Invalid parameters. Exiting...
else
if [ -z "$SSHK_COM" ]
then
SSHK_COM="$SSHK_DIR"
fi
echo : Generate
echo
mkdir "$HOME/.ssh/$SSHK_DIR"
ssh-keygen -t ed25519 -a 100 -C "$SSHK_COM" -f "$HOME/.ssh/$SSHK_DIR/id_ed25519"
if [ $? -eq 0 ]
then
echo
echo Key created: $HOME/.ssh/$SSHK_DIR/id_ed25519
if [ -z "$SSHK_NOCHAIN" ]
then
echo
echo : Add to key store
echo
ssh-add "$HOME/.ssh/$SSHK_DIR/id_ed25519"
if [ $? -eq 0 ]
then
echo Added successfully.
else
echo Issues encountered when attempting to add to key store. Retry manually.
fi
fi
else
echo
echo Key creation failed.
fi
fi
@ChlodAlejandro
Copy link
Author

To run:

curl https://gist.githubusercontent.com/ChlodAlejandro/0cf80eeefd79cf4686626d8d5312afbe/raw/ac9aa5b330279fef42fca87f17142d289e533f90/ssh-gen.sh | bash

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