Automatically creating Samba accounts with adduser
16 Aug 2008I'm setting up an environment with a lot of Windows users. This means using Samba.
On the samba server, each user has a unix account for mail, and a samba account. Setting up password syncing between unix accounts and samba accounts is described el is sewhere.
Now it would be nice if the "adduser" command also created a samba user. I've searched for a way to do this, and found no pre-baked solution.
"adduser" is a perlscript which calls "groupadd", "useradd" and "passwd" to create the user.
What I did is hijack the "useradd" command to execute "/usr/sbin/useradd" (What it was supposed to execute) and "smbpasswd -n -a username".
This is the script:
#!/usr/bin/perl
system "/usr/sbin/useradd", @ARGV;
my $ret = $?;
system "/usr/bin/smbpasswd", ("-n", "-a", $ARGV[-1]);
exit $ret;
Place it in "/root/bin/" and add "/root/bin/" to your PATH. "adduser" will now automagically create samba accounts aswell.