Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-17-2016, 05:16 AM   #1
Registered: Sep 2008
Posts: 505

Rep: Reputation: 37
script to automate "smbpasswd -a user"

I've written a script that installs samba on a new centos 7 64 bit server but I want the script to give the password when setting up the samba user. I've been trawling google for ages and there are examples out there but I can't get any of them to work. Most require that you manually input the smb-password but I want my script to do it automatically.
At the moment my script section is
(snip loads of install script>>
useradd <username>  # creates the unix user
<snip section that creates the user a/c passwd>
smbpasswd -a <username here>  # creates aamba user
here's where I always get the 'New SMB password:' prompt.

after 'smbpasswd -a <username here>' I've tried
(echo newpassword; echo confirmNewPassword) | smbpasswd -s
doesn't work, I also tried
(echo $pw; echo $pw ) | smbpasswd -s -a $user
doesn't work, along with many other lines that I've forgotten. What do I need after 'smbpasswd -a <username here>' to make this work? thanks for any help.

update: I did find this post here: but it's gives this output with two errors:
passwd: Authentication token manipulation error
Added user <username>
smbpasswd: option requires an argument -- 'w'
Added user <username>.

Last edited by tonj; 11-17-2016 at 05:33 AM.
Old 11-17-2016, 07:43 AM   #2
Registered: Aug 2002
Posts: 19,213

Rep: Reputation: 2992Reputation: 2992Reputation: 2992Reputation: 2992Reputation: 2992Reputation: 2992Reputation: 2992Reputation: 2992Reputation: 2992Reputation: 2992Reputation: 2992
Try using printf instead of echo

printf "$pw\$pw\n" | smbpasswd -a -s $user
Old 11-18-2016, 03:24 AM   #3
Registered: Sep 2008
Posts: 505

Original Poster
Rep: Reputation: 37
thankyou michael I did solve it in the end, the script at the link above does in fact work on a clean centos 7 install, I deleted the '-w' in it and it seemed to go okay and the samba share worked.


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
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 02:03 AM
[SOLVED] expect feature to automate login to target host and "sudo su - user" apss_evaluator Linux - Newbie 6 10-08-2015 03:53 AM
PostFix + ISPConfig mail return "unknown user" or "no such user here" Jacky444 Linux - Server 1 02-10-2010 05:21 PM
Sama problem with "smbpasswd" linuxy2 Linux - Server 5 03-05-2007 03:43 AM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 03:32 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:16 AM.

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