Last active
February 14, 2022 13:11
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run:
curl https://gist.githubusercontent.com/ChlodAlejandro/0cf80eeefd79cf4686626d8d5312afbe/raw/ac9aa5b330279fef42fca87f17142d289e533f90/ssh-gen.sh | bash