LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-04-2005, 11:40 PM   #1
dickohead
Member
 
Registered: Feb 2003
Location: Melbourne, VIC, Australia
Distribution: Ubuntu 6.06
Posts: 101

Rep: Reputation: 15
Shell Script to add samba users


hey guys,

i have the following code setting the password for normal users:
Code:
echo $password | /usr/bin/passwd --stdin $username
and I tried a similar thing when adding smb users:
Code:
echo $password | /usr/bin/smbpasswd -a --stdin $username
And of course the variables of $password and $username are set earlier on by "read" followed by lots of if's for validation..... trying to keep it neat, but it's just not working!

Any help on this would be greatly appreciated! As once i have figured out this problem it's onto doing the same thing with mysql!!! joy joy joy!
 
Old 04-04-2005, 11:55 PM   #2
ahwkong
Member
 
Registered: Aug 2004
Location: Australia
Distribution: Fedora
Posts: 282

Rep: Reputation: 30
For a start, "--stdin" is not a valid option for smbpasswd

To debug your script, I recommend you to run the script this way:

(says your script is "addsmbusr.sh")

Code:
bash -x addsmbusr.sh
Note any error message and post it here again.

BTW, I vaguely remember this is the kind of problem discussed in smb mailing list a long while ago. Search there and someone may have post a working script already.
 
Old 04-05-2005, 12:06 AM   #3
dickohead
Member
 
Registered: Feb 2003
Location: Melbourne, VIC, Australia
Distribution: Ubuntu 6.06
Posts: 101

Original Poster
Rep: Reputation: 15
there is no error given only that --stdin is an invalid option of smbpasswd..... will keep looking!
 
Old 04-05-2005, 12:08 AM   #4
dickohead
Member
 
Registered: Feb 2003
Location: Melbourne, VIC, Australia
Distribution: Ubuntu 6.06
Posts: 101

Original Poster
Rep: Reputation: 15
ahh..... if i read things more closely i would have noticed that giving the -s option alows stdin input :

#note to self: RTFM!!!
 
Old 04-05-2005, 02:51 PM   #5
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Thanks, you inspired me to take another look at my add user script and solved the samba password part.

The file /home/names.txt has the user names (lower case) , groups and the Linux/Samba password.
The Linux and Samba passwords are the same and the user should change them soon after login.
The groups can already exist.

For example.....

fred service 12qwaszx
sam hr 34erdfcv
joe maint 56tyghbn
sally sales 78uijkm

Code:
#!/bin/bash
#
# Ensure that root is running the script.
##
WHOAMI=`/usr/bin/whoami`
if [ $WHOAMI != "root" ]; then
echo "You must be root to add news users!"
exit 1
fi
#
clear
NEW_USERS="/home/names.txt"

cat ${NEW_USERS} | \
while read USER GROUP SMBPASS ; do
   
   groupadd ${GROUP} 2> /dev/null
   adduser ${USER} -g ${GROUP}

   (echo $SMBPASS; echo $SMBPASS) | passwd --stdin ${USER} > /dev/null
   echo Added user ${USER}

   smbpasswd -e ${USER} -w ${SMBPASS} > /dev/null
   (echo $SMBPASS; echo $SMBPASS) | smbpasswd -as ${USER}
   echo -e "${USER} = ${USER}" >> /etc/samba/smbusers
done
 
Old 04-05-2005, 04:30 PM   #6
ahwkong
Member
 
Registered: Aug 2004
Location: Australia
Distribution: Fedora
Posts: 282

Rep: Reputation: 30
Well, I guess it is a script for recovery or setting up a new machine, right? You don't create user a/c all over again once in a while :-)

Looks very neat. Gonna be useful for people who are also looking for this kind of tool.
 
Old 04-05-2005, 06:08 PM   #7
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Yeh, it would be mostly for new installs or setting up the new branch office with 100 new employees.
 
Old 11-29-2007, 03:11 AM   #8
tagbantay
LQ Newbie
 
Registered: Jun 2007
Posts: 7

Rep: Reputation: 0
good script... but i need some help with it...

hi guys...

i've read your forum and i find it very usefull and informative for me as a newbie... i really admire you guys for your abilities... which is why i posted this on...

i tried the script that was posted but unfortunately, i got some errors... can anyone help me with it? I used the exact script, but i got the error that says.. "INVALID OPTIONS --stdin for passwd", and when i tried to remove it i got this error: "PASSWORD DID NOT MATCH"... on my names.txt, I have this:

user1 group1 sq765
user2 group1 123kjl

something like that..


cany you point me to the right direction with this. I'm really tryn to learn my way out but... i dont know much about shell scripting so..


Thanks to you guys in advance and more power!!!
 
Old 11-30-2007, 01:16 AM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,847

Rep: Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584
Well, I did man passwd on Suse and the --stdin option is there.
1. What distro are you using?
2. you prob need to be root for that anyway....
 
Old 11-30-2007, 05:23 AM   #10
tagbantay
LQ Newbie
 
Registered: Jun 2007
Posts: 7

Rep: Reputation: 0
i used ubuntu 6.06... i tried man passwd also, but
i could not find --stdin option there...
also, i used root in executing the script and
when trying man passwd....

Last edited by tagbantay; 11-30-2007 at 05:28 AM.
 
Old 12-01-2007, 06:53 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,847

Rep: Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584
Ok, well just FYI, it's in
man passwd
on RH FC6 also... hmmm
Maybe try the Ubuntu forum here or over at ubuntuforums.org ?
 
Old 03-28-2012, 06:50 PM   #12
ishbuggy
LQ Newbie
 
Registered: Mar 2012
Posts: 1

Rep: Reputation: Disabled
What would be the best way to add a user to multiple groups be using this script? Thanks!
 
Old 11-17-2016, 04:40 AM   #13
tonj
Member
 
Registered: Sep 2008
Posts: 521

Rep: Reputation: 37
couple of errors with this script

@horney thanks v much for posting this script, I'm also trying to automate the adding of samba users to centos 7 64 bit however your script gives (me) two errors and I was hoping for some help. The output I get when i run your script is:
Code:
passwd: Authentication token manipulation error
Added user <username>
smbpasswd: option requires an argument -- 'w'
Added user <username>.
 
Old 11-17-2016, 01:05 PM   #14
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,583
Blog Entries: 11

Rep: Reputation: 3605Reputation: 3605Reputation: 3605Reputation: 3605Reputation: 3605Reputation: 3605Reputation: 3605Reputation: 3605Reputation: 3605Reputation: 3605Reputation: 3605
Quote:
Originally Posted by tonj View Post
@horney thanks v much for posting this script, I'm also trying to automate the adding of samba users to centos 7 64 bit however your script gives (me) two errors and I was hoping for some help. The output I get when i run your script is:
You have posted to a thread that has been inactive for nine years.

Please start your own new thread and provide a complete description of your current task, what you have tried and what errors or unexpected results that you received.This will assure that your question receives the attention it deserves.
 
Old 11-18-2016, 02:28 AM   #15
tonj
Member
 
Registered: Sep 2008
Posts: 521

Rep: Reputation: 37
@astrogeek I didn't notice the thread was nine years old however I found that the script does in fact work on a clean install of centos 7. I had to remove the '-w' but I ended up with a samba share that worked.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
add multiple users(Script) amer_58 Programming 22 02-22-2013 09:09 AM
Shell Script: Add Users from file flobadon Programming 3 12-07-2004 03:49 PM
Script to add users ssudhi Linux - Newbie 3 05-01-2004 04:33 AM
Script thats add users automatically embalmedlenin *BSD 1 09-14-2003 04:34 PM
Add User Shell Script DAC Programming 2 10-13-2002 03:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration