Skip to content

Instantly share code, notes, and snippets.

@devnoot
Created November 22, 2024 17:12
Show Gist options
  • Save devnoot/fd5ee4a1aba87382946adb1a8fb1a818 to your computer and use it in GitHub Desktop.
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)
#!/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