Skip to content

Instantly share code, notes, and snippets.

@sarkrui
Created October 31, 2023 14:21
Show Gist options
  • Save sarkrui/0b54011bfbe80162994e65f6e0b26055 to your computer and use it in GitHub Desktop.
Save sarkrui/0b54011bfbe80162994e65f6e0b26055 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Check if xclip is installed, install if not
if ! command -v xclip &>/dev/null; then
apt-get update
apt-get install -y xclip
fi
# Check if clipboard is empty
if [[ -z "$(xclip -o -selection clipboard 2>/dev/null)" ]]; then
echo "Clipboard is empty. Exiting."
exit 1
fi
# Check if ~/.ssh exists, create if not
if [[ ! -d "$HOME/.ssh" ]]; then
mkdir -p "$HOME/.ssh"
chmod 700 "$HOME/.ssh"
fi
# Check if /root/.ssh/authorized_keys exists, create if not
if [[ ! -f "/root/.ssh/authorized_keys" ]]; then
mkdir -p "/root/.ssh"
chmod 700 "/root/.ssh"
touch "/root/.ssh/authorized_keys"
chmod 600 "/root/.ssh/authorized_keys"
fi
# Paste clipboard content to /root/.ssh/authorized_keys
xclip -o -selection clipboard 2>/dev/null >> /root/.ssh/authorized_keys
@sarkrui
Copy link
Author

sarkrui commented Oct 31, 2023

One-click Installation

bash -c "$(curl -fsSL https://tinyurl.com/addSSHKeys)"

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