Last active
March 5, 2017 23:46
-
-
Save yugoslavskiy/3ba3f37053c57cdb01c3d2a0f330ebff 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
#!/usr/bin/env bash | |
# | |
# Arguments: | |
# - username | |
# - user pass | |
# - user rsa pub key | |
# | |
# This script: | |
# - creates user with password | |
# - adds user into sudoers and sshusers group | |
# - adds user's public key into his ${HOME}/.ssh/authorized_keys | |
# | |
# created date: 02.2016 | |
# last update date: 06.02.2017 | |
# author: @yugoslavskiy | |
# | |
user_name=$1 | |
user_pass=$2 | |
user_key=$3 | |
# for base debian 8.4 instllation | |
apt-get -y install sudo curl tmux htop | |
# create user | |
useradd -m ${user_name} | |
# change password | |
passwd ${user_name} << EOF | |
${user_pass} | |
${user_pass} | |
EOF | |
# place pub key | |
mkdir /home/${user_name}/.ssh | |
echo ${user_key} > /home/${user_name}/.ssh/authorized_keys | |
# permission setup | |
chmod 600 /home/${user_name}/.ssh/authorized_keys | |
chmod 755 /home/${user_name}/.ssh | |
chown -R ${user_name}:${user_name} /home/${user_name}/.ssh/ | |
# adding to groups | |
groupadd sshusers | |
usermod -a -G sshusers ${user_name} | |
echo "${user_name} ALL=(ALL) ALL" > /etc/sudoers.d/${user_name} | |
chmod 440 /etc/sudoers.d/${user_name} | |
# change default shell | |
chsh -s /bin/bash ${user_name} | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment