#!/bin/bash # Create ~/.ssh directory if it doesn't exist mkdir -p ~/.ssh chmod 700 ~/.ssh # Add your public key to authorized_keys (avoiding duplicates) KEY="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC... your-email@domain.com" if ! grep -Fxq "$KEY" ~/.ssh/authorized_keys 2>/dev/null; then echo "$KEY" >> ~/.ssh/authorized_keys echo "SSH public key added successfully!" else echo "SSH public key already exists" fi # Set proper permissions chmod 600 ~/.ssh/authorized_keys # Clean up any files with carriage returns if [ -f ~/.ssh/authorized_keys$'\r' ]; then cat ~/.ssh/authorized_keys$'\r' >> ~/.ssh/authorized_keys rm ~/.ssh/authorized_keys$'\r' echo "Cleaned up duplicate file with carriage returns" fi