Created
March 12, 2018 14:34
-
-
Save aytacworld/8dde85a3505a917790310b3afabd4f11 to your computer and use it in GitHub Desktop.
bash commend to run after installing a fresh vm on a cloud serviceprovider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
read -p "Enter your ip: " IP | |
read -p "Enter your hostname: (myserver) " HOSTNAME | |
read -p "Enter your domainname: (domain.com) " DOMAIN | |
FQDN=$HOSTNAME.$DOMAIN | |
# Update the system | |
apt-get update | |
apt-get upgrade -y | |
# Update hostname and hosts | |
printf ${HOSTNAME} > /etc/hostname | |
printf "127.0.0.1 ${FQDN} ${HOSTNAME} localhost localhost.localdomain\n\ | |
${IP} ${FQDN} ${HOSTNAME}\n\ | |
127.0.1.1 ${FQDN} ${HOSTNAME}\n" > /etc/hosts | |
# Update Locals | |
read -p "Enter local: (nl_BE.UTF-8) " LOCAL | |
export LANGUAGE=$LOCAL | |
export LANG=$LOCAL | |
export LC_ALL=$LOCAL | |
locale-gen $LOCAL | |
dpkg-reconfigure locales | |
# Update firewall | |
ufw allow 22 # ssh | |
ufw enable | |
# Create admin used | |
read -p "Do you want to create a sudo user? " CREATE_USER | |
case "$CREATE_USER" in | |
[jJyY]*) | |
mkdir /etc/skel/.ssh && cp .ssh/authorized_keys /etc/skel/.ssh/authorized_keys | |
read -p "Enter username: " USERNAME | |
adduser $USERNAME | |
usermod -aG admin,sudo $USERNAME | |
# Update sshd (disable root login if admin user is created) | |
sed -i -e 's/PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config | |
;; | |
esac | |
# Update sshd | |
sed -i -e 's/PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config | |
service ssh restart | |
# reboot machine | |
reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment