Skip to content

Instantly share code, notes, and snippets.

@devnoot
Created November 22, 2024 17:12

Revisions

  1. devnoot created this gist Nov 22, 2024.
    20 changes: 20 additions & 0 deletions setpermissions.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/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."