Add ssh-setup.sh
This commit is contained in:
parent
02615d5b85
commit
2db7a5099d
1 changed files with 34 additions and 0 deletions
34
ssh-setup.sh
Normal file
34
ssh-setup.sh
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
SSH_KEY="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGrc2BRE6hkdSyyQMykQin/5HCaLyzRuOvSgei9LJ2yE nikoa@Niko-hp-gamingpc-1"
|
||||
SSH_DIR="/root/.ssh"
|
||||
AUTHORIZED_KEYS="$SSH_DIR/authorized_keys"
|
||||
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo "[!] This script must be run as root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[+] Creating /root/.ssh if it doesn't exist..."
|
||||
mkdir -p "$SSH_DIR"
|
||||
chmod 700 "$SSH_DIR"
|
||||
|
||||
echo "[+] Adding your SSH key to /root/.ssh/authorized_keys..."
|
||||
touch "$AUTHORIZED_KEYS"
|
||||
grep -qxF "$SSH_KEY" "$AUTHORIZED_KEYS" || echo "$SSH_KEY" >> "$AUTHORIZED_KEYS"
|
||||
chmod 600 "$AUTHORIZED_KEYS"
|
||||
|
||||
echo "[+] Disabling password authentication for SSH..."
|
||||
sed -i 's/^#\?\s*PasswordAuthentication\s\+.*/PasswordAuthentication no/' /etc/ssh/sshd_config
|
||||
sed -i 's/^#\?\s*ChallengeResponseAuthentication\s\+.*/ChallengeResponseAuthentication no/' /etc/ssh/sshd_config
|
||||
|
||||
echo "[+] Restarting SSH service..."
|
||||
if command -v systemctl >/dev/null 2>&1; then
|
||||
systemctl restart sshd
|
||||
else
|
||||
service ssh restart
|
||||
fi
|
||||
|
||||
echo "[✓] Done. SSH key added and password login disabled for root."
|
||||
Loading…
Add table
Add a link
Reference in a new issue