Skip to content

Instantly share code, notes, and snippets.

@ITler
Forked from nils-wagner-signavio/create_user.sh
Last active February 11, 2020 10:19

Revisions

  1. ITler revised this gist Feb 11, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create_user.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #! /usr/bin/env bash

    # normally first char of prename + surname
    users="${@:-nwagner}"
    users="${@:-jsmith}"

    # normally users
    group="users"
  2. ITler revised this gist Aug 5, 2019. 1 changed file with 0 additions and 23 deletions.
    23 changes: 0 additions & 23 deletions commit-msg
    Original file line number Diff line number Diff line change
    @@ -1,23 +0,0 @@
    #!/bin/sh

    get_clean_message() {
    egrep -o '^[^#].*' "$1"
    }

    # Do not allow empty messages after removing comments
    [ -z "$(get_clean_message "$1")" ] && {
    echo >&2 Commit message cannot be empty.
    exit 1
    }

    # Prepend to message Jira issues found in branch name but not found within message
    JIRAS_IN_BRANCH_NAME="$(git rev-parse --abbrev-ref HEAD | egrep -io '\b[a-z]{3,}-[1-9][0-9]*\b')"
    for JIRA in ${JIRAS_IN_BRANCH_NAME}; do
    get_clean_message "$1" | egrep "\b${JIRA}\b" || sed -i "" -e "1s/^/${JIRA}, /" "$1"
    done
    if [ -z "${JIRAS_IN_BRANCH_NAME}" ]; then
    # Allow non prefixed commit messages, when branch name not referring JIRA issue
    get_clean_message "$1" | egrep -qi '\b[a-z]{3,}-[1-9][0-9]*\b' || {
    echo >&2 Commit message does not contain JIRA code. Consider amending message before pushing.
    }
    fi
  3. ITler revised this gist Aug 5, 2019. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions commit-msg
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/bin/sh

    get_clean_message() {
    egrep -o '^[^#].*' "$1"
    }

    # Do not allow empty messages after removing comments
    [ -z "$(get_clean_message "$1")" ] && {
    echo >&2 Commit message cannot be empty.
    exit 1
    }

    # Prepend to message Jira issues found in branch name but not found within message
    JIRAS_IN_BRANCH_NAME="$(git rev-parse --abbrev-ref HEAD | egrep -io '\b[a-z]{3,}-[1-9][0-9]*\b')"
    for JIRA in ${JIRAS_IN_BRANCH_NAME}; do
    get_clean_message "$1" | egrep "\b${JIRA}\b" || sed -i "" -e "1s/^/${JIRA}, /" "$1"
    done
    if [ -z "${JIRAS_IN_BRANCH_NAME}" ]; then
    # Allow non prefixed commit messages, when branch name not referring JIRA issue
    get_clean_message "$1" | egrep -qi '\b[a-z]{3,}-[1-9][0-9]*\b' || {
    echo >&2 Commit message does not contain JIRA code. Consider amending message before pushing.
    }
    fi
  4. ITler revised this gist Aug 1, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create_user.sh
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ for user in ${users}; do
    [ -f "${auth_keys_file}" ] || install -b -m 0600 /dev/null ${auth_keys_file}
    if [[ -r ${all_auth_keys_file} && $(grep ${user} ${all_auth_keys_file}) ]]; then
    echo "Found user's SSH key in authorized_keys database ${all_auth_keys_file} file"
    cat ${all_auth_keys_file} >> ${auth_keys_file}
    cat ${all_auth_keys_file} >>${auth_keys_file}
    else
    echo "SSH key for user ${user} not found in authorized_keys database ${all_auth_keys_file}, so add key manually"
    echo "Now paste user's SSH pub key here, make sure to end with new line and press CTRL+D to exit"
  5. ITler revised this gist Aug 1, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create_user.sh
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ group="users"
    # normally adm and/or sudo
    groups="adm,sudo"

    # optional file containing all known SSH pub keys in authorized_key format
    # optional file containing all known SSH pub keys in authorized_keys format
    all_auth_keys_file=$(dirname $0)/authkeys

    for user in ${users}; do
  6. ITler revised this gist Aug 1, 2019. 1 changed file with 12 additions and 3 deletions.
    15 changes: 12 additions & 3 deletions create_user.sh
    Original file line number Diff line number Diff line change
    @@ -9,15 +9,24 @@ group="users"
    # normally adm and/or sudo
    groups="adm,sudo"

    # optional file containing all known SSH pub keys in authorized_key format
    all_auth_keys_file=$(dirname $0)/authkeys

    for user in ${users}; do
    auth_keys_file=/home/${user}/.ssh/authorized_keys
    echo "Creating access for user: ${user}"
    useradd -s /bin/bash -m ${user} -g ${group} -G ${groups} -c "manually created on $(date +%Y%m%d-%H%M%S)"
    mkdir -m 0700 /home/${user}/.ssh
    [ -f "${auth_keys_file}" ] || install -b -m 0600 /dev/null ${auth_keys_file}
    echo "Paste user's SSH pub key here, make sure to end with new line and press CTRL+D to exit"
    echo ${auth_keys_file}
    cat >>${auth_keys_file}
    if [[ -r ${all_auth_keys_file} && $(grep ${user} ${all_auth_keys_file}) ]]; then
    echo "Found user's SSH key in authorized_keys database ${all_auth_keys_file} file"
    cat ${all_auth_keys_file} >> ${auth_keys_file}
    else
    echo "SSH key for user ${user} not found in authorized_keys database ${all_auth_keys_file}, so add key manually"
    echo "Now paste user's SSH pub key here, make sure to end with new line and press CTRL+D to exit"
    echo ${auth_keys_file}
    cat >>${auth_keys_file}
    fi
    sed -i "/.*${user}.*/!d" ${auth_keys_file}
    echo "SSH pub key stored in ${auth_keys_file}"
    chown -R ${user}:${group} $(dirname ${auth_keys_file})
  7. ITler revised this gist Jul 1, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create_user.sh
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ for user in ${users}; do
    echo "Paste user's SSH pub key here, make sure to end with new line and press CTRL+D to exit"
    echo ${auth_keys_file}
    cat >>${auth_keys_file}
    sed -i "/.*${user}.*/\!d" ${auth_keys_file}
    sed -i "/.*${user}.*/!d" ${auth_keys_file}
    echo "SSH pub key stored in ${auth_keys_file}"
    chown -R ${user}:${group} $(dirname ${auth_keys_file})
    echo -e "... User '${user}' done\n"
  8. ITler revised this gist Jul 1, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create_user.sh
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ for user in ${users}; do
    echo "Paste user's SSH pub key here, make sure to end with new line and press CTRL+D to exit"
    echo ${auth_keys_file}
    cat >>${auth_keys_file}
    sed -i "" "/.*${user}.*/\!d" ${auth_keys_file}
    sed -i "/.*${user}.*/\!d" ${auth_keys_file}
    echo "SSH pub key stored in ${auth_keys_file}"
    chown -R ${user}:${group} $(dirname ${auth_keys_file})
    echo -e "... User '${user}' done\n"
  9. ITler revised this gist Jul 1, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create_user.sh
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ for user in ${users}; do
    echo "Paste user's SSH pub key here, make sure to end with new line and press CTRL+D to exit"
    echo ${auth_keys_file}
    cat >>${auth_keys_file}
    sed -i "" "/.*${u}.*/\!d" ${auth_keys_file}
    sed -i "" "/.*${user}.*/\!d" ${auth_keys_file}
    echo "SSH pub key stored in ${auth_keys_file}"
    chown -R ${user}:${group} $(dirname ${auth_keys_file})
    echo -e "... User '${user}' done\n"
  10. ITler revised this gist Jul 1, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions create_user.sh
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,7 @@ for user in ${users}; do
    echo "Paste user's SSH pub key here, make sure to end with new line and press CTRL+D to exit"
    echo ${auth_keys_file}
    cat >>${auth_keys_file}
    sed -i "" "/.*${u}.*/\!d" ${auth_keys_file}
    echo "SSH pub key stored in ${auth_keys_file}"
    chown -R ${user}:${group} $(dirname ${auth_keys_file})
    echo -e "... User '${user}' done\n"
  11. @nils-wagner-signavio nils-wagner-signavio revised this gist May 13, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create_user.sh
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ users="${@:-nwagner}"
    # normally users
    group="users"

    # normally adm and or sudo
    # normally adm and/or sudo
    groups="adm,sudo"

    for user in ${users}; do
  12. @nils-wagner-signavio nils-wagner-signavio created this gist May 13, 2019.
    24 changes: 24 additions & 0 deletions create_user.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #! /usr/bin/env bash

    # normally first char of prename + surname
    users="${@:-nwagner}"

    # normally users
    group="users"

    # normally adm and or sudo
    groups="adm,sudo"

    for user in ${users}; do
    auth_keys_file=/home/${user}/.ssh/authorized_keys
    echo "Creating access for user: ${user}"
    useradd -s /bin/bash -m ${user} -g ${group} -G ${groups} -c "manually created on $(date +%Y%m%d-%H%M%S)"
    mkdir -m 0700 /home/${user}/.ssh
    [ -f "${auth_keys_file}" ] || install -b -m 0600 /dev/null ${auth_keys_file}
    echo "Paste user's SSH pub key here, make sure to end with new line and press CTRL+D to exit"
    echo ${auth_keys_file}
    cat >>${auth_keys_file}
    echo "SSH pub key stored in ${auth_keys_file}"
    chown -R ${user}:${group} $(dirname ${auth_keys_file})
    echo -e "... User '${user}' done\n"
    done