Skip to content

Instantly share code, notes, and snippets.

@smashnet
Created February 8, 2019 14:37
Show Gist options
  • Select an option

  • Save smashnet/48873e70db97c864295f5fb398b63472 to your computer and use it in GitHub Desktop.

Select an option

Save smashnet/48873e70db97c864295f5fb398b63472 to your computer and use it in GitHub Desktop.

Revisions

  1. smashnet created this gist Feb 8, 2019.
    21 changes: 21 additions & 0 deletions add_no_shell_user.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #!/bin/bash

    if [ -z "$1" ]; then
    echo "Please provide a name for the new user!"
    exit 1
    fi

    echo "Creating user and group -$1- and adding you ($(whoami)) to that group."
    echo -n "Sure ye wanna do this? (y/N) -> "

    read answer

    if [ "$answer" == "y" ] || [ "$answer" == "Y" ]; then
    echo "Doing it so!"
    sudo useradd -r -s /sbin/nologin $1
    sudo usermod -a -G $1 $(whoami)
    echo "Done!"
    echo $(id $1)
    else
    echo "Ok, did not do anything... bye!"
    fi