Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Forked from klaemo/initial.sh
Last active January 4, 2016 01:49

Revisions

  1. @maxogden maxogden revised this gist Jan 22, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions initial.sh
    Original file line number Diff line number Diff line change
    @@ -36,6 +36,7 @@ if [ ! -d /home/$NEW_USER ]; then

    printf '\e[1;34m%b\e[m' "\nGranting sudo rights to $NEW_USER\n"
    adduser $NEW_USER sudo
    echo "admin ALL = NOPASSWD: ALL" >> /etc/sudoers

    # make ssh a little more secure
    printf '\e[1;34m%b\e[m' "\nDisabling ssh root login...\n"
  2. @maxogden maxogden revised this gist Jan 22, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion initial.sh
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,6 @@ apt-get -y -qq install ufw
    ufw allow ssh
    ufw allow http
    ufw allow https
    ufw allow 8080
    echo "y" | ufw enable
    ufw status

  3. @maxogden maxogden revised this gist Jan 22, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions initial.sh
    Original file line number Diff line number Diff line change
    @@ -44,3 +44,5 @@ if [ ! -d /home/$NEW_USER ]; then
    sed -e 's/#\{0,1\}PasswordAuthentication .*$/PasswordAuthentication no/' -i /etc/ssh/sshd_config
    reload ssh
    fi

    exit
  4. @maxogden maxogden revised this gist Jan 22, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions initial.sh
    Original file line number Diff line number Diff line change
    @@ -22,6 +22,8 @@ ufw allow 8080
    echo "y" | ufw enable
    ufw status

    NEW_USER="${NEW_USER:-admin}"

    if [ ! -d /home/$NEW_USER ]; then
    printf '\e[1;34m%b\e[m' "\nCreating user '$NEW_USER'...\n"
    adduser --disabled-password --gecos "" $NEW_USER
  5. @maxogden maxogden revised this gist Jan 22, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion initial.sh
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ ufw status

    if [ ! -d /home/$NEW_USER ]; then
    printf '\e[1;34m%b\e[m' "\nCreating user '$NEW_USER'...\n"
    adduser --gecos "" $NEW_USER
    adduser --disabled-password --gecos "" $NEW_USER
    mkdir /home/$NEW_USER/.ssh
    chmod 700 /home/$NEW_USER/.ssh

  6. @maxogden maxogden revised this gist Jan 22, 2014. 1 changed file with 12 additions and 16 deletions.
    28 changes: 12 additions & 16 deletions initial.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,4 @@
    #!/bin/bash
    # usage: ./initial.sh
    #
    # - updates ubuntu
    # - creates a sudo-able non-root user called $user_name (for logging into the server later and doing stuff)
    # - sets up ssh keys for that user by copying the over from /root/.ssh
    @@ -12,7 +10,17 @@ printf '\e[1;34m%b\e[m' "\nUpdating the system...\n"
    apt-get -y -qq update
    DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade

    NEW_USER=$1
    printf '\e[1;34m%b\e[m' "\nCreating user 'taco'...\n"
    adduser --system --group --gecos "" taco

    printf '\e[1;34m%b\e[m' "\nSetting up basic firewall...\n"
    apt-get -y -qq install ufw
    ufw allow ssh
    ufw allow http
    ufw allow https
    ufw allow 8080
    echo "y" | ufw enable
    ufw status

    if [ ! -d /home/$NEW_USER ]; then
    printf '\e[1;34m%b\e[m' "\nCreating user '$NEW_USER'...\n"
    @@ -32,17 +40,5 @@ if [ ! -d /home/$NEW_USER ]; then
    printf '\e[1;34m%b\e[m' "\nDisabling ssh root login...\n"
    sed -e 's/^PermitRootLogin .*$/PermitRootLogin no/' -i /etc/ssh/sshd_config
    sed -e 's/#\{0,1\}PasswordAuthentication .*$/PasswordAuthentication no/' -i /etc/ssh/sshd_config
    reload ssh
    fi

    printf '\e[1;34m%b\e[m' "\nCreating user 'taco'...\n"
    adduser --system --group --gecos "" taco

    printf '\e[1;34m%b\e[m' "\nSetting up basic firewall...\n"
    apt-get -y -qq install ufw
    ufw allow ssh
    ufw allow http
    ufw allow https
    ufw allow 8080
    echo "y" | ufw enable
    ufw status
    reload ssh
  7. @maxogden maxogden revised this gist Jan 22, 2014. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions initial.sh
    Original file line number Diff line number Diff line change
    @@ -5,14 +5,14 @@
    # - creates a sudo-able non-root user called $user_name (for logging into the server later and doing stuff)
    # - sets up ssh keys for that user by copying the over from /root/.ssh
    # - disables ssh root login (that's what $user_name is for)
    # - creates a system user "taco"
    # - creates a system user "taco" for the taco process to run as
    # - sets up basic iptables firewall
    #
    printf '\e[1;34m%b\e[m' "\nUpdating the system...\n"
    apt-get -y -qq update
    apt-get -y upgrade
    DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade

    NEW_USER=taco
    NEW_USER=$1

    if [ ! -d /home/$NEW_USER ]; then
    printf '\e[1;34m%b\e[m' "\nCreating user '$NEW_USER'...\n"
    @@ -32,7 +32,6 @@ if [ ! -d /home/$NEW_USER ]; then
    printf '\e[1;34m%b\e[m' "\nDisabling ssh root login...\n"
    sed -e 's/^PermitRootLogin .*$/PermitRootLogin no/' -i /etc/ssh/sshd_config
    sed -e 's/#\{0,1\}PasswordAuthentication .*$/PasswordAuthentication no/' -i /etc/ssh/sshd_config
    reload ssh
    fi

    printf '\e[1;34m%b\e[m' "\nCreating user 'taco'...\n"
    @@ -46,3 +45,4 @@ ufw allow https
    ufw allow 8080
    echo "y" | ufw enable
    ufw status
    reload ssh
  8. @maxogden maxogden revised this gist Jan 22, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions initial.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #!/bin/bash
    # usage: ./initial.sh taco
    # usage: ./initial.sh
    #
    # - updates ubuntu
    # - creates a sudo-able non-root user called $user_name (for logging into the server later and doing stuff)
    @@ -12,7 +12,7 @@ printf '\e[1;34m%b\e[m' "\nUpdating the system...\n"
    apt-get -y -qq update
    apt-get -y upgrade

    NEW_USER=$1
    NEW_USER=taco

    if [ ! -d /home/$NEW_USER ]; then
    printf '\e[1;34m%b\e[m' "\nCreating user '$NEW_USER'...\n"
  9. @maxogden maxogden revised this gist Jan 22, 2014. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion initial.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,13 @@
    #!/bin/bash
    # usage: ./initial.sh taco
    #
    # - updates ubuntu
    # - creates a sudo-able non-root user called $user_name (for logging into the server later and doing stuff)
    # - sets up ssh keys for that user by copying the over from /root/.ssh
    # - disables ssh root login (that's what $user_name is for)
    # - creates a system user "taco"
    # - sets up basic iptables firewall
    #
    printf '\e[1;34m%b\e[m' "\nUpdating the system...\n"
    apt-get -y -qq update
    apt-get -y upgrade
    @@ -35,4 +45,4 @@ ufw allow http
    ufw allow https
    ufw allow 8080
    echo "y" | ufw enable
    ufw status
    ufw status
  10. @klaemo klaemo created this gist Jan 21, 2014.
    38 changes: 38 additions & 0 deletions initial.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    printf '\e[1;34m%b\e[m' "\nUpdating the system...\n"
    apt-get -y -qq update
    apt-get -y upgrade

    NEW_USER=$1

    if [ ! -d /home/$NEW_USER ]; then
    printf '\e[1;34m%b\e[m' "\nCreating user '$NEW_USER'...\n"
    adduser --gecos "" $NEW_USER
    mkdir /home/$NEW_USER/.ssh
    chmod 700 /home/$NEW_USER/.ssh

    printf '\e[1;34m%b\e[m' "\nAdding ssh keys to $NEW_USER...\n"
    cp /root/.ssh/authorized_keys /home/$NEW_USER/.ssh/
    chmod 400 /home/$NEW_USER/.ssh/authorized_keys
    chown $NEW_USER:$NEW_USER /home/$NEW_USER -R

    printf '\e[1;34m%b\e[m' "\nGranting sudo rights to $NEW_USER\n"
    adduser $NEW_USER sudo

    # make ssh a little more secure
    printf '\e[1;34m%b\e[m' "\nDisabling ssh root login...\n"
    sed -e 's/^PermitRootLogin .*$/PermitRootLogin no/' -i /etc/ssh/sshd_config
    sed -e 's/#\{0,1\}PasswordAuthentication .*$/PasswordAuthentication no/' -i /etc/ssh/sshd_config
    reload ssh
    fi

    printf '\e[1;34m%b\e[m' "\nCreating user 'taco'...\n"
    adduser --system --group --gecos "" taco

    printf '\e[1;34m%b\e[m' "\nSetting up basic firewall...\n"
    apt-get -y -qq install ufw
    ufw allow ssh
    ufw allow http
    ufw allow https
    ufw allow 8080
    echo "y" | ufw enable
    ufw status