Passwortänderung durch Unraid-SMB/Share-User per SSH ermöglichen

(Please scroll down for information in English)

Es ist ein bekanntes Manko von Unraid, dass die Änderung des SMB-Passworts nicht durch die jeweiligen Benutzer selbst, sondern nur mit Hilfe des Administrators möglich ist. Ab einer gewissen Anzahl Benutzer scheidet Unraid hierdurch als Serversystem häufig aus.

Das folgende Script ermöglicht jedem Unraid-Benutzer die eigenständige Passwortänderung per SSH, sei es über die Kommandozeile oder vielleicht schöner mit Web-based SSH oder dem Plugin „Command Line“.


# allowsmbpwchange 1.0 - 02/2024 by Jan Richert, https://krefcom.eu
# Ermoeglicht Passwortaenderung durch Unraid-SMB/Share-User per SSH
# Getestet mit Unraid 6.12.6
#
# 1. Script ablegen als /boot/config/allowsmbpwchange
# 2. echo bash /boot/config/allowsmbpwchange >> /boot/config/go
# 3. In Unraid unter Settings -> Management Access: Use ssh aktivieren
# 4. Unraid neu starten
# 5. SMB-Passwortaenderung z.B. von Windows mit "ssh servername -l username", Passwort s.u.
#
# Konfiguration
#
# SMB-Mindestpasswortlaenge bei Aenderung durch User.
# Soll der hier waehrend der ersten Ausfuehrung gesetzte Wert veraendert werden, muss nach
# Aenderung die Datei /tmp/.allowsmbpwchange_1strun geloescht werden.
#
MINPASSWORDLENGTH=8
#
# Alle wie viel Minuten sollen geaenderte SMB-Passwoerter auf den USB-Stick gesichert werden,
# um bei einem reboot erhalten zu bleiben? Dieser Wert gibt auch an, alle wie viel Minuten
# die SMB-Passwortaenderung durch User fuer neu angelegte User freigeschaltet wird.
# Soll der hier waehrend der ersten Ausfuehrung gesetzte Wert veraendert werden, muss nach
# Aenderung die Datei /tmp/.allowsmbpwchange_1strun geloescht werden.
#
UPDATEINTERVAL=30
#
# Zur SMB-Passwortaenderung melden sich User mit ihrem Namen und dem folgenden Passwort per SSH an.
# Dieses Passwort kann auch leer sein, dies hat allerdings zur Folge, dass die User
# im Dashboard als "unprotected" angezeigt werden, was irrelevant ist, da sie ja ein SMB-Passwort haben.
# Ohne aktuelles SMB-Passwort kann natuerlich auch kein neues vergeben werden. Deshalb spielt
# es auch keine Rolle, dass das hier definierte Passwort fuer alle identisch ist.
#
PASSWORD="pwchg"
#
# Ende Konfiguration
#
allow () {
if [ "$1" != "root" ]
then
chsh -s /usr/bin/smbpasswd $1
if [ ! -z $PASSWORD ]
then
echo "$1:$PASSWORD" | chpasswd
else
echo "$1:" | chpasswd -e
fi
fi
}

if [ ! -f /tmp/.allowsmbpwchange_1strun ]
then
pdbedit -P "min password length" -C $MINPASSWORDLENGTH
echo /usr/bin/smbpasswd >> /etc/shells
sed -i.bak '/^UsePAM .*/s/^#*/#/g ; /^AllowUsers .*/s/^#*/#/g ; /^#PermitEmptyPasswords no$/s/^#*//g ; /PermitEmptyPasswords no/s/no/yes/' /etc/ssh/sshd_config
/etc/rc.d/rc.sshd reload
echo -e "# allowsmbpwchange\n*/$UPDATEINTERVAL * * * * /bin/bash /boot/config/allowsmbpwchange > /dev/null 2>&1" > /boot/config/plugins/dynamix/allowsmbpwchange.cron
/usr/local/sbin/update_cron
touch /tmp/.allowsmbpwchange_1strun
fi
/usr/bin/pdbedit -L -w > /boot/config/smbpasswd
while read line ; do
user=$( echo "$line" |cut -d\: -f1 )
allow $user
done < /boot/config/smbpasswd

Summary in English:

It is a well-known shortcoming of Unraid that changing the SMB password is not possible by the respective users themselves, but only with the help of the administrator. Therefore once there is a certain number of users, Unraid is often excluded as a suitable server system.

This script enables every Unraid user to change their password independently via SSH, be it using the command line or perhaps nicer with Web-based SSH or using the plugin „Command Line“.

Configuration section in English:

# 1st step: Store the script as /boot/config/allowsmbpwchange
# 2nd step: echo bash /boot/config/allowsmbpwchange >> /boot/config/go
# 3rd step: Activate in Unraid under Settings -> Management Access: Use ssh
# 4th step: Restart Unraid
# 5th step: SMB password change e.g. from Windows with „ssh servername -l username“, password see below.
#
# Configuration
#
# SMB minimum password length when changed by user. If the value set here during the first execution is changed,
# the file /tmp/.allowsmbpwchange_1strun is to be deleted afterwards.
#
MINPASSWORDLENGTH=8
#
# Changed SMB passwords should be saved to the USB stick every how many minutes to be preserved in case of reboot?
# This value also indicates every how many minutes the SMB password change by user is activated for newly created users.
# If the value set here during the first execution is changed, the file /tmp/.allowsmbpwchange_1strun is to be deleted afterwards.
#
UPDATEINTERVAL=30
#
# To change the SMB password, users log in via SSH with their name and the following password.
# This password could also be empty, but this would cause the users to be shown as „unprotected“ in the dashboard,
# which is irrelevant since they still have a SMB password. Of course, a new SMB password cannot be assigned
# without knowledge of the current SMB password. That’s why it doesn’t matter that the password defined here is
# the same for everyone.
#
PASSWORD=“pwchg“
#
# End of configuration

Kommentar verfassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Nach oben scrollen