Skip to content

Instantly share code, notes, and snippets.

@souzagab
Created August 22, 2021 19:25
Show Gist options
  • Save souzagab/f1372b79677686399ce0257e0ad9d1d7 to your computer and use it in GitHub Desktop.
Save souzagab/f1372b79677686399ce0257e0ad9d1d7 to your computer and use it in GitHub Desktop.
Generate and add key to Github (via Github CLI)
#!/bin/bash
echo -e "This script will generate a new ssh-key without an passphrase.\n"
echo -e "\nEnter the desired e-mail:"
read -p "E-mail: " EMAIL
echo -e "\n Enter a key name (will be saved on $HOME/.ssh/):"
read -p "Key: " KEY
KEY_LOCATION="$HOME/.ssh/$KEY"
# TODO: Dinamic key location, and type
ssh-keygen -N "" -t ed25519 -C "$EMAIL" -f $KEY_LOCATION
eval "$(ssh-agent -s)"
echo -e "\n\n"
ssh-add $KEY_LOCATION
echo -e "\n"
# Assuming Debian/Ubuntu distro (apt)
echo -e "Installing Github CLI .\n"
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install -y gh
echo -e "Login to Github via CLI .\n"
gh auth login
echo -e "\n Adding ssh-key to github"
gh ssh-key add $KEY_LOCATION
echo -e "\n Assert everthing is successfull\n"
ssh -T [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment