getpubkey.sh
| @@ -6,6 +6,8 @@ read -p "Enter your GitHub username: " USERNAME | |||
| 6 | 6 | # Get the GitHub public key URL | |
| 7 | 7 | KEY_URL="https://github.com/$USERNAME.keys" | |
| 8 | 8 | ||
| 9 | + | pushd ~/.ssh/ | |
| 10 | + | ||
| 9 | 11 | # Download the public key | |
| 10 | 12 | wget -q -O - "$KEY_URL" > ~/.ssh/authorized_keys | |
| 11 | 13 | ||
getpubkey.sh(файл создан)
| @@ -0,0 +1,21 @@ | |||
| 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 | + | # Download the public key | |
| 10 | + | wget -q -O - "$KEY_URL" > ~/.ssh/authorized_keys | |
| 11 | + | ||
| 12 | + | # Set appropriate permissions for the authorized_keys file | |
| 13 | + | chmod 600 ~/.ssh/authorized_keys | |
| 14 | + | ||
| 15 | + | # Check if the .ssh directory exists and create it if it doesn't | |
| 16 | + | if [ ! -d ~/.ssh ]; then | |
| 17 | + | mkdir -p ~/.ssh | |
| 18 | + | chmod 700 ~/.ssh | |
| 19 | + | fi | |
| 20 | + | ||
| 21 | + | echo "Public key successfully added to authorized_keys" | |
Новее
Позже