Last active
November 10, 2024 11:38
-
-
Save 3265/54d0339408e8cd1898af6694b983736f to your computer and use it in GitHub Desktop.
boilerplate to generate github settings in a new remote instance.
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 | |
# 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ 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