Sysadmin-console is a simple python script to enable non-Linux-users to perform some basic system administration (user management) tasks. This script was written for Debian. The script shows how to use pexpect to drive system utilities from python.
Features: List users, add system user, change user password, delete system user.
Install python packages pexpect (python package for "expect"-like behavior) and "getpass". Add an user "sysadmin" with shell "sysadmin-console". Use sudo to give this user rights to execute /usr/bin/passwd, etc.
Using pexpect to control smbpasswd:
import pexpect
print "Changing samba password.."
child = pexpect.spawn("sudo /usr/bin/smbpasswd %s" % (username,))
child.expect(".* password:\s*")
child.sendline(password)
child.expect(".* password:\s*")
child.sendline(password)
child.read()
child.close()