Skip to content

Instantly share code, notes, and snippets.

@isurfer21
Created July 15, 2025 04:02
Show Gist options
  • Select an option

  • Save isurfer21/202ea5ed4b149e4b8d08ea4847b13a40 to your computer and use it in GitHub Desktop.

Select an option

Save isurfer21/202ea5ed4b149e4b8d08ea4847b13a40 to your computer and use it in GitHub Desktop.

Revisions

  1. isurfer21 created this gist Jul 15, 2025.
    20 changes: 20 additions & 0 deletions generate_ssh_key.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/bin/bash

    # Set the key file path
    KEY_PATH="$HOME/.ssh/id_rsa"

    # Check if the SSH key already exists
    if [ -f "$KEY_PATH.pub" ]; then
    echo "SSH key already exists at $KEY_PATH.pub"
    else
    echo "Generating a new SSH key..."
    ssh-keygen -t rsa -b 4096 -f "$KEY_PATH" -N ""
    echo "SSH key generated."
    fi

    # Display the public key
    echo "Your public SSH key is:"
    cat "$KEY_PATH.pub"

    # Optional: Copy to remote system (uncomment and edit the line below)
    # ssh-copy-id user@remote_host