Octoprint user import

Is it at all possible to automatically sync user profiles across multiple octoprint instances? We are using octoprint as a way to control which uses which printer but we want to avoid having to type everybody's username and password 3 separate times during a class of 6-10. Any insight would be extremely helpful

Make717 innovation center 3D printing area
make717.org

If I were you, I think I would create a bash script that creates all the users, put this on a USB drive and then run it once per printer instance.

I'm guessing that OctoPrint uses the native Linux user/group/password mechanism so hopefully anyone can correct me if I'm wrong. /BadAdvice

You could also easily use scp to copy the script sideways. You could also use ssh to remotely run commands in batch to all three printers; creating a script on your own workstation. See here for details. /BadAdvice

I haven't tried the following script so maybe it would need some tweaking. I'm just writing it out of my head, so-to-speak. You would run this on your workstation. /BadAdvice

create-users.sh

#!/bin/sh
for s in huey duey louie
do
  echo "Setting up $s..."
  bash="/bin/bash"
  username="tom"
  group="somegroup"
  password="raspberry"
  homedir="/home/$username"
  ssh -t pi@$s.local "useradd -g $group -s $bash -d $homedir -m $username"
  ssh -t pi@$s.local "echo $password | passwd $username --stdin"
  # Repeat for other users like this...
  username="dick"
  password="raspberry"
  homedir="/home/$username"
  ssh -t pi@$s.local "useradd -g $group -s $bash -d $homedir -m $username"
  ssh -t pi@$s.local "echo $password | passwd $username --stdin"
  username="harry"
  password="raspberry"
  homedir="/home/$username"
  ssh -t pi@$s.local "useradd -g $group -s $bash -d $homedir -m $username"
  ssh -t pi@$s.local "echo $password | passwd $username --stdin"
done

Make sure to mark the script on your own workstation as executable. /BadAdvice

Have a look at accessControl configuration in the docs. User accounts are configured in a separate yaml file, defaulting to users.yaml in your configuration directory. I haven't tried this (sorry, don't have access control turned on my instance at all), but you can probably just sync this file across your instances to get user accounts going everywhere.

Automating copying that across all of your instances could happen in a few ways. A barebones method would be a script running periodically on a "primary" instance that uses rsync to update the other secondary ones. Or you could use a shared volume, either in-house with samba or external with dropbox or similar.

1 Like