getpubkey.sh
· 553 B · Bash
Sin formato
#!/bin/bash
# Prompt the user for their GitHub username
read -p "Enter your GitHub username: " USERNAME
# Get the GitHub public key URL
KEY_URL="https://github.com/$USERNAME.keys"
pushd ~/.ssh/
# Download the public key
wget -q -O - "$KEY_URL" > ~/.ssh/authorized_keys
# Set appropriate permissions for the authorized_keys file
chmod 600 ~/.ssh/authorized_keys
# Check if the .ssh directory exists and create it if it doesn't
if [ ! -d ~/.ssh ]; then
mkdir -p ~/.ssh
chmod 700 ~/.ssh
fi
echo "Public key successfully added to authorized_keys"
| 1 | #!/bin/bash |
| 2 | |
| 3 | # Prompt the user for their GitHub username |
| 4 | read -p "Enter your GitHub username: " USERNAME |
| 5 | |
| 6 | # Get the GitHub public key URL |
| 7 | KEY_URL="https://github.com/$USERNAME.keys" |
| 8 | |
| 9 | pushd ~/.ssh/ |
| 10 | |
| 11 | # Download the public key |
| 12 | wget -q -O - "$KEY_URL" > ~/.ssh/authorized_keys |
| 13 | |
| 14 | # Set appropriate permissions for the authorized_keys file |
| 15 | chmod 600 ~/.ssh/authorized_keys |
| 16 | |
| 17 | # Check if the .ssh directory exists and create it if it doesn't |
| 18 | if [ ! -d ~/.ssh ]; then |
| 19 | mkdir -p ~/.ssh |
| 20 | chmod 700 ~/.ssh |
| 21 | fi |
| 22 | |
| 23 | echo "Public key successfully added to authorized_keys" |