Skip to content

Instantly share code, notes, and snippets.

@3265
Last active November 10, 2024 11:38
Show Gist options
  • Save 3265/54d0339408e8cd1898af6694b983736f to your computer and use it in GitHub Desktop.
Save 3265/54d0339408e8cd1898af6694b983736f to your computer and use it in GitHub Desktop.
boilerplate to generate github settings in a new remote instance.
#!/bin/bash
# ref: https://stackoverflow.com/questions/43235179/how-to-execute-ssh-keygen-without-prompt
#!/bin/bash
# Check if argument is provided
if [ $# -ne 1 ]; then
echo "Error: Please provide a name for the SSH key"
echo "Usage: $0 <key-name>"
exit 1
fi
KEY_NAME=$1
# Create .ssh directory if it doesn't exist
mkdir -p ~/.ssh/
cd ~/.ssh/
# Generate SSH key
yes | ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_${KEY_NAME}_rsa
if [ $? -ne 0 ]; then
echo "Error: Failed to generate SSH key"
exit 1
fi
# Set proper permissions
sudo chmod -R 700 ~/.ssh/
sudo chmod 600 ~/.ssh/id_${KEY_NAME}_rsa
# Add config entry
cat >> config <<EOF
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_${KEY_NAME}_rsa
EOF
# Display public key
cat ~/.ssh/id_${KEY_NAME}_rsa.pub
@3265
Copy link
Author

3265 commented Nov 5, 2022

$ wget https://gist.githubusercontent.com/3265/54d0339408e8cd1898af6694b983736f/raw/c57bb85e9133fbd233c78ec58ad33a0044ea6b70/github.sh
$ sudo chmod +x github.sh
$ ./github.sh xxx
$ # paste public key to github
$ ssh -T git@github.com

and then

$ git config --global user.name "Your Name"
$ git config --global user.email "you@example.com"

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