Skip to content

Instantly share code, notes, and snippets.

@JoshData
Last active November 26, 2020 17:59
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save JoshData/615aa18cecb8a6596f59 to your computer and use it in GitHub Desktop.
Save JoshData/615aa18cecb8a6596f59 to your computer and use it in GitHub Desktop.
rstudio multi-user helper
#!/bin/bash
# Start an AWS instance with one of the AMIs provided by:
# http://www.louisaslett.com/RStudio_AMI/
#
# Get this script.
# wget https://gist.githubusercontent.com/JoshData/615aa18cecb8a6596f59/raw/1b43765552862af98cb16d95dd236a81f6c5b464/build_logins.sh
# chmod +x build_logins.sh
#
# Then use this script to create many logins on the system.
#
# sudo ./build_logins.sh 50
#
# * This creates 50 users named user1, user2, ...
# * The passwords are the same as the user names.
# * The home directory of each is set to /mnt/$user, so you can put
# them on a large volume, and each is initialized with a copy of the
# "rstudio" user's home directory, so you can login as rstudio (pw: rstudio)
# first, get it set up how you want, and then run this script to create clones.
#
# Running the script again trashes all of those users and regenerates new ones.
# stop rstudio because it runs instances as the users we are trying to delete
rstudio-server stop
sleep 1 # might take time to release
# clear out any previously generated logins
existing_users=$(grep ^user /etc/passwd | sed 's/:.*//')
if [ ! -z "$existing_users" ]; then
for user in $existing_users; do
deluser --remove-home $user > /dev/null
done
fi
# make new ones, specify the count on the comand line!
for id in $(seq 1 $1); do
userhome=/mnt/user$id
adduser \
--gid 1001 \
--home $userhome \
--no-create-home \
--quiet --gecos "" \
--shell /bin/false \
--disabled-password \
user$id < /dev/null
cp -a /home/rstudio $userhome
chown -R user$id $userhome
echo "user$id:user$id" | chpasswd
done
# start again
rstudio-server start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment