Skip to content

Instantly share code, notes, and snippets.

@bcalik
Forked from faytekin/add_ssh_key.sh
Last active October 7, 2020 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcalik/7154caad8d7f252c93e4d9efc6e167e9 to your computer and use it in GitHub Desktop.
Save bcalik/7154caad8d7f252c93e4d9efc6e167e9 to your computer and use it in GitHub Desktop.
Add my ssh-key to UBUNTU root
#!/bin/bash
# Add my ssh-key to ubuntu root user and active ssh root login
# Login as root or run with sudo
# wget -q -O - "https://gist.github.com/bcalik/7154caad8d7f252c93e4d9efc6e167e9/raw" | bash -
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
MY_SSH_KEY='ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIK4WSOTMP0FD2x0c4srykEEYInHS9TvOQ7M9VSwMbMFN burak@macellan.net'
mkdir -p /root/.ssh
echo $MY_SSH_KEY >> /root/.ssh/authorized_keys
# sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
# sed -i 's/#AuthorizedKeysFile/AuthorizedKeysFile/g' /etc/ssh/sshd_config
if [ -d /run/systemd/system ]; then
systemctl restart ssh
else
service ssh restart
fi
echo "Done"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment