SSH Key Deployment

by mkorsak
23 deployments · 1 still active · last rev. 1 year ago

This script deploys a Linode with your SSH key preinstalled on the root account and SSH password authentication disabled.

Compatible with: CentOS 7, Debian 8, Ubuntu 16.04 LTS, Debian 7, Ubuntu 14.04 LTS
						#!/bin/bash
#
#<UDF name="ssh" label="SSH Public Key:">
# SSH=
#

# This updates the packages on the system from the distribution repositories.
apt-get update
apt-get upgrade -y

# This sets your public key on your Linode
mkdir ~/.ssh
echo "${SSH}" >> ~/.ssh/authorized_keys

# This disables password authentication
sed -i 's/#*PasswordAuthentication [a-zA-Z]*/PasswordAuthentication no/' /etc/ssh/sshd_config

# This restarts the SSH service, with two commands to cover more distributions
systemctl restart sshd
service ssh restart