Bahls Ubuntu Setup

by danielbahl
2 deployments · 0 still active · last rev. 26 days ago

Creates a new user and sets SSH Key
Disable ssh root login
Set timezone on server

Compatible with: Ubuntu 16.04 LTS, Ubuntu 16.10
# <udf name="tz" Label="Timezone" default="Europe/Copenhagen" example="Local timezone, ex. Europe/Copenhagen" />
# <udf name="hostname" Label="Hostname (server)" />
# <udf name="sshkey" Label="SSHKey (public)" />
# <udf name="hostnamefull" Label="Full Hostname (" />
# <udf name="username" Label="Username for new sudo user" />
# <udf name="userpass" Label="User Password for new sudo user" />
source <ssinclude StackScriptID="1">

apt-get update
apt-get -y install aptitude

echo "$HOSTNAME" > /etc/hostname
hostname -F /etc/hostname

IP=$(ifconfig eth0 | awk -F: '/inet addr:/ {print $2}' | awk '{ print $1 }')

echo $IP "$HOSTNAMEFULL" "$HOSTNAME" >> /etc/hosts

mkdir /root/.ssh
echo "$SSHKEY" >> /root/.ssh/authorized_keys
chmod 0700 /root/.ssh
chmod 0600 /root/.ssh/authorized_keys

adduser $USERNAME --disabled-password --gecos ""
echo "$USERNAME:$USERPASS" | chpasswd
usermod -aG sudo "$USERNAME"

mkdir -p /home/$USERNAME/.ssh
echo "$SSHKEY" >> /home/$USERNAME/.ssh/authorized_keys
chown -R $USERNAME:$USERNAME /home/$USERNAME/.ssh/authorized_keys
chmod 0700 /home/$USERNAME/.ssh
chmod 0600 /home/$USERNAME/.ssh/authorized_keys

sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config

cp -vf /usr/share/zoneinfo/$TZ /etc/localtime
sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config

apt-get install -y git

sed -i -e 's/^#PS1=/PS1=/' /root/.bashrc # enable the colorful root bash prompt
sed -i -e "s/^#alias ll='ls -l'/alias ll='ls -al'/" /root/.bashrc # enable ll list long alias <3

apt-get -y install language-pack-da
sh -c "echo 'LC_ALL=en_US.UTF-8\nLANG=en_US.UTF-8' >> /etc/environment"
dpkg-reconfigure locales

add-apt-repository ppa:ondrej/php
apt-get update

git clone /root/.vim_runtime
sh /root/.vim_runtime/