Created
November 22, 2024 17:12
-
-
Save devnoot/fd5ee4a1aba87382946adb1a8fb1a818 to your computer and use it in GitHub Desktop.
Bash script to set your ssh folder permissions (or setup your .ssh directory properly)
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/env bash | |
# Create the .ssh directory if it does not exist. | |
if [ ! -d ~/.ssh ]; then | |
mkdir -p ~/.ssh | |
fi | |
# Create the .ssh config file if it does not exist. | |
if [ ! -f ~/.ssh/config ]; then | |
touch ~/.ssh/config | |
fi | |
# Set the correct permissions for ssh directory and keys | |
chmod 700 ~/.ssh | |
find ~/.ssh -type f -name "*.pub" -exec chmod 644 {} \; | |
find ~/.ssh \( -type f \( -name "*.pem" -o ! -name "*.*" \) \) -exec chmod 600 {} \; | |
chmod 600 ~/.ssh/config | |
# Confirmation message | |
echo "SSH directory and file permissions have been updated." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment