Skip to content

Instantly share code, notes, and snippets.

@jmlrt
Created March 28, 2016 21:59
Show Gist options
  • Save jmlrt/12394daf937f2c9a370f to your computer and use it in GitHub Desktop.
Save jmlrt/12394daf937f2c9a370f to your computer and use it in GitHub Desktop.
deploy ssh keys, configure sudo and install salt on new debian server
#!/bin/sh
#
# deploy ssh keys, configure sudo and install salt on new debian server
# require config file .myenv with variables MYUSER and SSHPUBKEY
source_my_env()
{
if [ -f ${MYENV} ]
then
. ${MYENV}
else
printf "ERROR: ENV file ${MYENV} not found"
exit 1
fi
}
get_home_dir()
{
USER=$1
grep ${USER} /etc/passwd | awk -F: '{print $6}'
}
deploy_ssh_keys()
{
for user in root ${MYUSER}
do
HOMEDIR=$(get_home_dir ${user})
test -d ${HOMEDIR}/.ssh || mkdir ${HOMEDIR}/.ssh
chmod 700 ${HOMEDIR}/.ssh
printf ${SSHPUBKEY} >> ${HOMEDIR}/.ssh/authorized_keys
chmod 600 ${HOMEDIR}/.ssh/authorized_keys
chown -R ${user}:${user} ${HOMEDIR}
done
}
config_sudo()
{
apt-get -y install sudo
printf "${MYUSER} ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers
}
upgrade_os()
{
apt-get update && apt-get -y dist-upgrade
}
install_salt()
{
test -d /etc/apt/sources.list.d || mkdir /etc/apt/sources.list.d
printf "deb http://debian.saltstack.com/debian wheezy-saltstack main" >> /etc/apt/sources.list.d/saltstack.list
wget -q -O- "http://debian.saltstack.com/debian-salt-team-joehealy.gpg.key" | apt-key add -
apt-get -y install salt-minion
}
#*** MAIN ***
MYENV="$(dirname $0)/.myenv"
source_my_env
printf "1. configure ssh keys for users jmlrt and root"
deploy_ssh_keys
printf "2. upgrade os"
upgrade_os
printf "3. configure sudo"
config_sudo
printf "4. install saltstack"
install_salt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment