Created
October 31, 2023 14:21
-
-
Save sarkrui/0b54011bfbe80162994e65f6e0b26055 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One-click Installation