2024-11-07 19:44:15 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-11-07 20:11:34 +08:00
|
|
|
PUB_KEY=$(curl -fsSL https://git.myprog.top/eric.keys)
|
2024-12-27 11:45:56 +08:00
|
|
|
if [ ! -f "/root/.ssh/authorized_keys" ]; then
|
|
|
|
mkdir -p /root/.ssh/
|
|
|
|
touch /root/.ssh/authorized_keys
|
2024-11-07 19:44:15 +08:00
|
|
|
fi
|
|
|
|
|
2024-12-27 11:45:56 +08:00
|
|
|
echo -e "${PUB_KEY}\n" > /root/.ssh/authorized_keys
|
2024-11-07 19:44:15 +08:00
|
|
|
|
2024-12-27 11:45:56 +08:00
|
|
|
chmod 700 /root/.ssh/
|
|
|
|
chmod 600 /root/.ssh/authorized_keys
|
2024-11-07 19:44:15 +08:00
|
|
|
|
|
|
|
sudo sed -i "s@.*\(PasswordAuthentication \).*@\1no@" /etc/ssh/sshd_config
|
|
|
|
sudo sed -i 's/#\?PubkeyAuthentication \(yes\|no\)/PubkeyAuthentication yes/' /etc/ssh/sshd_config
|
|
|
|
sudo sed -i 's/^#AuthorizedKeysFile/AuthorizedKeysFile/' /etc/ssh/sshd_config
|
|
|
|
|
|
|
|
sudo systemctl restart sshd
|
|
|
|
|
|
|
|
echo "Done"
|