Skip to content

Instantly share code, notes, and snippets.

@pandada8
Last active April 25, 2017 21:00
Show Gist options
  • Save pandada8/9d3c756a3c1e1e847ba6b3353bf8801d to your computer and use it in GitHub Desktop.
Save pandada8/9d3c756a3c1e1e847ba6b3353bf8801d to your computer and use it in GitHub Desktop.
node-init.sh
sed -i "s/jessie/stretch/g" /etc/apt/sources.list && apt update -y && apt dist-upgrade -y && printf "net.ipv4.tcp_congestion_control=bbr\nnet.core.default_qdisc=fq" >> /etc/sysctl.conf
#!/bin/bash
USER=pan
KEY="https://github.com/pandada8.keys"
function pwgen(){
dd if=/dev/urandom count=1 bs=20 2>/dev/null | base64 -w0 | sed -e 's/[+=\/]//g' | head -c $1
}
set -x
read NODE
echo "set hostname to $NODE"
hostnamectl set-hostname $NODE
echo 'Acquire::PDiffs "false";' > /etc/apt/apt.conf
apt update
apt install vim git zsh sudo wget curl tmux libpam-google-authenticator mosh iperf3 mtr -y
mkdir -p ~/.ssh/
chmod 0700 ~/.ssh/
wget $KEY -O ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
# echo -e "auth required pam_google_authenticator.so\n$(cat /etc/pam.d/sshd)" > /etc/pam.d/sshd
# sed -i -e 's/ChallengeResponseAuthentication no/ChallengeResponseAuthentication yes/g' /etc/ssh/sshd_config
sed -i -e 's/PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config | true
echo "Configure locale"
# google-authenticator -t -f -Q ANSI -r 1 -R 30 -d -w 4
sed -i -e "s/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g" /etc/locale.gen | true
locale-gen
echo "add users"
PASS=$(pwgen 20)
useradd -m -g users $USER -p $PASS -s /bin/zsh
echo "Configure sudo"
echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers
visudo -c
echo "Configure user"
sudo -H -u $USER KEY=$KEY /bin/zsh << 'EOF'
cd $HOME
git clone --recursive https://github.com/pandada8/prezto.git $HOME/.zprezto
setopt EXTENDED_GLOB
for rcfile in $HOME/.zprezto/runcoms/^README.md(.N); do
ln -s "$rcfile" ~/."${rcfile:t}"
done
mkdir -p ~/.ssh
chmod 700 ~/.ssh
wget $KEY -O ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
EOF
echo "New User: $USER"
echo "New User Password: $PASS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment