Skip to content

Instantly share code, notes, and snippets.

@faytekin
Created February 18, 2020 12:09
Show Gist options
  • Save faytekin/474ba0104165924b8850eb7385f7fcc6 to your computer and use it in GitHub Desktop.
Save faytekin/474ba0104165924b8850eb7385f7fcc6 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/faytekin/474ba0104165924b8850eb7385f7fcc6/raw" | bash -
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
MY_SSH_KEY='ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDkLX6G4ePw1pLRrOXDF2yvPmtkiVZi0dQMTE9ib1abMmJt7QXIySqbkpXqKTBgUxEe1SdRfuxYlRBrezje+Oe0ujhfa0UzJMQEcp1vk2lrj2SrIuql0ZTR/BT3Ni40qFY85VA6MVLnNjNo3KXR43Tyxz+NO+9FGMqTbvkfBQCHEB9O0hZ4Rj9Vd1EMbtMW+KQCZ+z471rYj0C6+roZMRN65uUheVwY52minNbg6QcVL1JYoXystlUy7kXEa2fgxsW4lmFYQfPeHwDurCZZsZ9mch/EnBVCjysu+rNzG1NnMTx/9T1cC7QkpW3hDuWArZ859E8/S0ATlmFSANox6AyUUscKMFkCODuYub0Povn5u3k+cTKAhdDnOZ4Vbo8cwvdxWT8CfsHRrmDSCuFLvewlUZUEPVIFkFxau404nEDe1BHjdwIfBnYE3oim9YMdvvYGRvmVkORkAWG9odrHlHAxB3oA6bdgjPAHH2JjJsmU0/C3yxt8QQYwdIr1dpOGKWiqK/Tz3BMF6CBaVp6J5BeXTxhsCvp0vAOOTiWT6ktR431ejeDjnpMCoSbTTOOjRQYJLecl6TCiof575+2IYkEM4gOOs4Ezst+nsyApA6Y3c13CgdEuv+yVMz8K4Z4gNmDIir1Aw09XNgdOnqz36fLLy0NRN0Cb8x1HHZrsbSPh+Q== fatih@aytekin.me'
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