Skip to content

Instantly share code, notes, and snippets.

@nils-wagner-signavio
Last active August 12, 2019 11:50
Show Gist options
  • Select an option

  • Save nils-wagner-signavio/83e6e4bbfe422bbf5e4fd76839270dcb to your computer and use it in GitHub Desktop.

Select an option

Save nils-wagner-signavio/83e6e4bbfe422bbf5e4fd76839270dcb to your computer and use it in GitHub Desktop.

Revisions

  1. 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
  2. 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