Root user w/ SSH key

by stevestreza
22 deployments · 8 still active · last rev. 4 years ago

Base server that sets a root SSH key and disables password auth. Used by me for Ansible-based deploys.

Compatible with: Debian 8, Debian 9, Ubuntu 16.04 LTS, Ubuntu 17.04
						#! /bin/bash
#
# Base server that sets a root SSH key and disables password auth. Used by me for Ansible-based deploys.
# <UDF name="root_ssh_key"  Label="Root user RSA SSH key" />
#
# If not deploying to Linode, set these environment variables. All required:
#  - ROOT_SSH_KEY: the contents of an SSH public key. SSH will be locked out of password auth.

mkdir -p /root/.ssh
echo "$ROOT_SSH_KEY" > /root/.ssh/authorized_keys
sed -i '' -e "s/\#PasswordAuthentication yes/PasswordAuthentication no/g" /etc/ssh/sshd_config
chmod -R 700 /root/.ssh;

# restart SSH
/etc/init.d/ssh restart