Friday, December 5, 2014

2 Bash Script to create Samba user and give samba password to samba user


 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! A !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Step 1 => Create script

Note : login with root user on your terminal 

#vim smbuser.sh      

#!/bin/bash
for USER in nirmal test2 test3 test4 test5
do

useradd -r -s /bin/false  $USER
PASSINPUT=`echo $USER|cut -c1-3`123 
(echo $PASSINPUT ; echo $PASSINPUT)  | smbpasswd -s -a $USER
done


# Now save this script


Step 2 => Run script to create users

#chmod +x  smbuser.sh
#./smbuser.sh

Added user nirmal.
Added user test2.
Added user test3.
Added user test4.
Added user test5.

Note : This script will create user test1 test2 test3 test4 test5 and set first 3 character and 123 for there password . 
For Example : nirmal user password is nir123 .


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!B!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

if you have thousand of user the you can take input from file also follow below
step.

Step 1 => Create a file and write all samba user name in the file like below
format.
Note : login with root user on your terminal  

 #vim /root/user.txt
 nirmal
 test1
 test2
 test3
 test4

#vim smbuser.sh      
#!/bin/bash
for USER in `cat /root/user.txt`
do

useradd -r -s /bin/false  $USER
PASSINPUT=`echo $USER|cut -c1-3`123 
(echo $PASSINPUT ; echo $PASSINPUT)  | smbpasswd -s -a $USER
done

# Now save this script

Step 2 => Run script to create users

#chmod +x  smbuser.sh
#./smbuser.sh

Added user nirmal.
Added user test2.
Added user test3.
Added user test4.
Added user test5.

Note : This script will create user nirmal test2 test3 test4 test5 and set first 3 character and 123 for there password . 
For Example : nirmal user password is nir123 .

6 comments:

  1. I like Your posts Very helpful for me

    ReplyDelete
  2. hi, I have a little modification on this script, but it always appears prompt password. Is there something important that I miss?
    this my modification
    #!/bin/bash
    for USER in `cat /data/master/user.txt`
    do
    samba-tool user create $USER
    PASS=`echo $USER|cut -c1-3`tinG@123
    (echo $PASS ; echo $PASS) | su - $USER
    done

    ReplyDelete
  3. Hi , if I want to set password as name+123(not only first 3 of the user). How can we do this for adding samba users only not Linux.

    ReplyDelete

Mastering Cron Jobs in Linux: A Comprehensive Guide with Examples

Introduction: Cron jobs are an indispensable tool in the world of system administration and automation. They allow users to schedule tasks t...