Skip to content

Instantly share code, notes, and snippets.

@ShiponKarmakar
Last active June 14, 2025 21:07
Show Gist options
  • Select an option

  • Save ShiponKarmakar/25805ff4e89766a37465e14b09925cb3 to your computer and use it in GitHub Desktop.

Select an option

Save ShiponKarmakar/25805ff4e89766a37465e14b09925cb3 to your computer and use it in GitHub Desktop.
Shell Scripts
#!/bin/bash
# Create .ssh directory if it doesn't exist
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# Add Shipon's public key to authorized_keys
echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDcYgxwJwFRdm7Wdo5/u8eB82oL1MwmTChrpCLOK/Cwd/W/4d82H5xrUQ0ZPzgxKZq/h9AkCtzGyGHEZnqfiOQmq+8TJ3YSHizKuq10DE3co2z73idBlpPftEe0xYI+NUYN1b1EeMZRItJtKfMK4mvQQRa9semGGR6Em3FQeEgOgVJUu1KCU13Cl0m+yYjxbBVC61s5BFydNMpBnpKgQKjdfPi/TPj+Oe1QpRG8IwoIbm1GKLDx99dlipweTUtjfQ8Tk0RGeuvAY9ICJIyI0OJl0cOELZxLsd6Vx8b3Ohzz4LoZN2tOeJzBq5bb0C5Tq5eHRY6NoVirdrbRrY7UhTGkX33yohS+Dg4NC+uvVb0K3/EJUnY2eWvgWDER43hOlytYEtwypb33m7EY+x697rz+Gn4rqx8mADN1jCICGUq3TVY3XV3i5aIswkw3kdF6NtPoCn6chYxc21huTN6XbJa/LU5Cd7LStqyuUeZw6LWfHyEnI/VTKCszxPCdEDZ/01fE5wrbvTa1VEL+OGLJXDUZofekp2rMgwH62yGt7dfQrZTkjWVLgMK9SNC72bS19QERM76TsmQ0vq/OBMyb4igc68XQFvIvxStmLH35TlE0cCJSK7xuIKqPCDrKlnOlz5cm9OKFdVLiVJYK25Q799SjBkWRPkA0uFGjo9VN2xvfLw== shiponkormoker@gmail.com" >> ~/.ssh/authorized_keys
# Ensure correct permissions
chmod 600 ~/.ssh/authorized_keys
# Confirmation message
echo "✅ SSH key added successfully for Shipon Karmakar."
#!/bin/bash
KEY_NAME="shipon_id_rsa"
KEY_PATH="$HOME/.ssh/$KEY_NAME"
AUTH_KEYS="$HOME/.ssh/authorized_keys"
if [ ! -f "$AUTH_KEYS" ]; then
echo "❌ authorized_keys file not found."
exit 1
fi
if [ ! -f "${KEY_PATH}.pub" ]; then
echo "❌ Public key file not found: ${KEY_PATH}.pub"
exit 1
fi
PUB_KEY=$(cat "${KEY_PATH}.pub")
if grep -Fxq "$PUB_KEY" "$AUTH_KEYS"; then
grep -vF "$PUB_KEY" "$AUTH_KEYS" > "${AUTH_KEYS}.tmp" && mv "${AUTH_KEYS}.tmp" "$AUTH_KEYS"
echo "✅ Shipon public key removed from authorized_keys."
else
echo "❌ Shipon public key not found in authorized_keys."
fi
#!/bin/bash
# Get server hostname
HOSTNAME=$(hostname)
# Detect SSH port from sshd_config, default to 22 if not found
SSH_PORT=$(grep -E "^Port " /etc/ssh/sshd_config | awk '{print $2}')
if [ -z "$SSH_PORT" ]; then
SSH_PORT=22
fi
# Get current user (the user running this script)
SSH_USER=$(whoami)
# File names
KEY_NAME="shipon_id_rsa"
KEY_PATH="$HOME/.ssh/$KEY_NAME"
# Create .ssh directory if not exists
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# Generate SSH key for Shipon if not already exists
if [ -f "$KEY_PATH" ]; then
echo "⚠️ SSH key already exists at $KEY_PATH"
else
echo "🔐 Generating new SSH key for Shipon..."
ssh-keygen -t rsa -b 2048 -f "$KEY_PATH" -C "${HOSTNAME}-Shipon <shiponkormoker@gmail.com>" -N ""
fi
# Add the public key to authorized_keys
cat "${KEY_PATH}.pub" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
# Output login info
echo -e "\n✅ SSH key created and added to authorized_keys."
echo "🔐 Please send the following private key to Shipon securely:"
echo "---------------------------------------------------------"
cat "$KEY_PATH"
echo "---------------------------------------------------------"
echo -e "\n🚀 Login details for Shipon:"
echo " Host/IP : $(curl -s https://ipinfo.io/ip)"
echo " Port : $SSH_PORT"
echo " Username : $SSH_USER"
echo " Key Label : ${HOSTNAME}-Shipon"
echo -e "\n📧 Email to: shiponkormoker@gmail.com"
echo -e "\n⚠️ NEVER send this via plain text. Use a secure channel (GDrive, ProtonMail, etc)."
@ShiponKarmakar
Copy link
Author

ShiponKarmakar commented May 31, 2025

bash <(curl -s https://gist.githubusercontent.com/ShiponKarmakar/25805ff4e89766a37465e14b09925cb3/raw/406bbc4502974c3ee441d9b253063fd1437c5163/setup_shipon_key.sh)

bash <(wget -qO- https://gist.githubusercontent.com/ShiponKarmakar/25805ff4e89766a37465e14b09925cb3/raw/406bbc4502974c3ee441d9b253063fd1437c5163/setup_shipon_key.sh)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment