Created
August 17, 2016 20:40
-
-
Save ajbrown/92d10bd83d468d33966971862963dc5c to your computer and use it in GitHub Desktop.
Create a new user, with a random password, allowing public key authentication
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 | |
# Usage: setup_user.sh <username> <path-to-pub-key> | |
# | |
# Credit to TechRepublic.com for inspiration: | |
USERNAME=$1 | |
KEYPATH=$2 | |
useradd -s /bin/bash -m $USERNAME | |
openssl rand -base64 8 | tee -a /home/$USERNAME/.password | passwd --stdin $USERNAME | |
chmod 600 /home/$USERNAME/.password | |
mkdir -p /home/$USERNAME/.ssh | |
chmod 700 /home/$USERNAME/.ssh | |
cp $KEYPATH /home/$USERNAME/.ssh/authorized_keys | |
chmod 600 /home/$USERNAME/.ssh/authorized_keys | |
chown -R $USERNAME:$USERNAME /home/$USERNAME/.ssh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment