creating samba user non interactively with smbpasswd

858 views
Skip to first unread message

ElectroMech :- Vibrant GNU/Linux User Group

unread,
Jul 25, 2009, 6:27:44 AM7/25/09
to VGLUG
Hi,

If you have 1000 or more users and you need to create is as samba
users it is very difficult to create it.

But following two command will do it for you very easily.

You need to use something like while loop or so.

#(echo password ; echo passowrd) |smbpasswd -a -s -U nilesh

or you can use

#echo -e "password\npassword" |smbpasswd -a -s -U nilesh


Remember "password" should be same as you required to repeat it twice.


Nilesh J. Vaghela
ElectroMech


ElectroMech :- Vibrant GNU/Linux User Group

unread,
Jul 25, 2009, 6:28:42 AM7/25/09
to VGLUG
Hi,

My typo mistake. Sorry!!!

On Jul 25, 3:27 pm, "ElectroMech :- Vibrant GNU/Linux User Group"
<nileshj.vagh...@gmail.com> wrote:
> Hi,
>
> If you have 1000 or more users and you need to create is as samba
> users it is very difficult to create it.
>
> But following two command will do it for you very easily.
>
> You need to use something like while loop or so.
>
> #(echo password ; echo passowrd) |smbpasswd -a -s -U nilesh

#(echo password ; echo password) |smbpasswd -a -s -U nilesh

Jay

unread,
Jul 27, 2009, 1:23:03 AM7/27/09
to VGLUG
Hi,

while running the same command on samba server I am getting following
error.

#echo world;echo world|smbpasswd -a -s -U xyz
world
Mismatch - password unchanged.
Unable to get new password.


On Jul 25, 3:28 pm, "ElectroMech :- Vibrant GNU/Linux User Group"

niraj vara

unread,
Jul 27, 2009, 1:29:16 AM7/27/09
to VG...@googlegroups.com
Please try this



for u in `cat yourfilename`
do
echo  passwd >  mm
echo passwd  >> mm
smbpasswd -s -a  $u < mm
done
--
Niraj M. Vara
Linux Administrator
Indian  Institute of Management  Ahmedabad
Mobile : 9898221954

"DON'T TELL ME THE SKY IS THE LIMIT, THERE ARE FOOTPRINTS ON THE MOON"

Kaushal Patel

unread,
Jul 27, 2009, 5:21:41 AM7/27/09
to VG...@googlegroups.com
Hi,

Here is script that help you to add user in Linux. It will also add it to Samba and provide quota if configured.


#################################################3
#!/bin/bash
username=$1
password=$2
whoami=`whoami`
datecreated=`date`
# Ensure that root is running the script.

if [ $whoami != "root" ]; then
        clear
        echo "You must be root to add news users!"
        exit 1
else
        clear
        useradd -g 501 $username > /dev/null
        echo $password | passwd --stdin $username > /dev/null
        echo "User $username has been created successfully."
        (echo $password; echo $password) | smbpasswd -as $username >
/dev/null
        setquota -u $username 4000000 5000000 0 0 -a /home /dev/null
        echo "User $username has been added as samba user successfully."
        echo $username $password $datecreated >> /var/log/usercreated
fi
############################################### 

Regards.
Kaushal Patel
Network and Security Engineer
Cyberoam QA
Elitecore Technologies Ltd.

Nilesh J. Vaghela

unread,
Jul 27, 2009, 7:17:47 AM7/27/09
to VG...@googlegroups.com
I do not know why people can not even copy and paste the command. :(

Jay wrote:
> Hi,
>
> while running the same command on samba server I am getting following
> error.
>
> #echo world;echo world|smbpasswd -a -s -U xyz
>

This was not my command.


> world
> Mismatch - password unchanged.
> Unable to get new password.
>

So you are getting errors.


>>> #(echo password ; echo passowrd) |smbpasswd -a -s -U nilesh
>>>

This was my command above one.

You forgot the brackets. !!!

--
Nilesh Vaghela
ElectroMech
Redhat Channel Partner and Training Partner
Ahmedabad: 404,Maulik Arcad,Nr. Mansi cross Road,Satellite Rd
Baroda : 25, The Emperor, Fatehgunj
www.electromech.info


Reply all
Reply to author
Forward
0 new messages