Skip to content

Instantly share code, notes, and snippets.

@SimFre
Created September 17, 2025 12:09
Show Gist options
  • Select an option

  • Save SimFre/8d4c988b37318ce555acf476a4404a46 to your computer and use it in GitHub Desktop.

Select an option

Save SimFre/8d4c988b37318ce555acf476a4404a46 to your computer and use it in GitHub Desktop.
Remote ZFS
#!/usr/bin/env bash
# This will allow the remote user to SSH to the machine
# and manage an isolated ZFS dataset.
REMOTEUSER=myremoteuser
useradd -s /usr/bin/rbash $REMOTEUSER
mkdir -p /home/$REMOTEUSER
cd /home/$REMOTEUSER
mkdir -p bin
mkdir -p .ssh
echo "ssh-ed25519 AAAAC............lfz root@$REMOTEUSER" >>.ssh/authorized_keys
chown -R $REMOTEUSER .ssh
chmod -R 0700 .ssh
find .ssh -type f -exec chmod 0600 "{}" \;
cat <<"EOF"
# Restricted BASH settings
# https://www.howtogeek.com/718074/how-to-use-restricted-shell-to-limit-what-a-linux-user-can-do/
unset -f $(compgen -A function)
complete -r
PATH="$HOME/bin"
export PATH
EOF
ln -s ../../../usr/sbin/zfs bin/zfs
ln -s ../../../usr/sbin/mbuffer bin/mbuffer
ln -s .rbash_profile .bashrc
ln -s .rbash_profile .profile
touch .hush_login
zfs allow $REMOTEUSER create,destroy,mount,receive,userprop tank/$REMOTEUSER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment