Last active
July 28, 2019 19:13
-
-
Save Joker-vD/ac79e0da078e901be360658d2daa3833 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
NEW_USERNAME=joker | |
test -n "$NEW_USERNAME" | |
command -v sudo >/dev/null | |
test -x /bin/bash | |
adduser --shell=/bin/bash "$NEW_USERNAME" | |
adduser "$NEW_USERNAME" sudo | |
NEW_HOMEDIR="$( getent -- passwd "$NEW_USERNAME" | cut -d: -f6 )" | |
test -n "$NEW_HOMEDIR" | |
cd -- "$NEW_HOMEDIR" | |
chown_and_mod() { | |
chown -- "$NEW_USERNAME:$NEW_USERNAME" "$2" | |
chmod -- "$1" "$2" | |
} | |
NEW_SSHDIR="$NEW_HOMEDIR/.ssh" | |
mkdir -- "$NEW_SSHDIR" | |
chown_and_mod 700 "$NEW_SSHDIR" | |
NEW_AUTHKEYS_FILE="$NEW_SSHDIR/authorized_keys" | |
IFS= read -p 'Enter a new entry for authorized_keys file: ' PUBKEY_LINE | |
printf '%s\n' "$PUBKEY_LINE" >> "$NEW_AUTHKEYS_FILE" | |
chown_and_mod 600 "$NEW_AUTHKEYS_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment