Piping password to smbpasswd

smbpasswd file
smbpasswd list users
smbpasswd username
default samba password
smb password
samba password database
etc smbpasswd
smbpasswd check if user exists

How can I pipe the new password to smbpasswd so I can automate my installation process.

Thanks to Mark I found the answer:

(echo newpassword; echo confirmNewPassword) | smbpasswd -s

BTW: (echo oldpasswd; echo newpasswd) | smbpasswd -s does not work.

Script samba password but securely, I want to script the addition on a samba user and the password. I have seen solutions similar to the one here. Piping password to smbpasswd echo -ne "$​PASS  Provided that your smb.conf contains passdb backend = tdbsam you can export a file with encrypted passwords, on a system that was already setup, using:. sudo pdbedit -e smbpasswd:/tmp/smbpasswd

I use the following in one of my scripts:

   echo -ne "$PASS\n$PASS\n" | smbpasswd -a -s $LOGIN

With echo:

-e : escape sequences, like \n

-n : don't add implicit newline at end

With smbpasswd:

-a : add new user

-s : silent

smbpasswd, When run as a normal user it allows the user to change the password used for their SMB sessions on any machines that store SMB passwords. By default (​when  automation - Piping password to smbpasswd . How can I pipe the new password to smbpasswd so I can automate my installation process.…

Try something like this:

(echo oldpasswd; echo newpasswd) | smbpasswd -s

Piping password to smbpasswd - automation - html, How can I pipe the new password to smbpasswd so I can automate my installation process. Thanks to Mark I found the answer: (echo newpassword; echo  How can I pipe the new password to smbpasswd so I can automate my installation process.… .net - Creating temporary folders I am working on a program that needs to create a multiple temporary folders for the application.

Use this echo 'somepassword' | tee - | smbpasswd -s

PykotaSetupNotesAddT.., Set a password for the demouser account. passwd demouser 3. NOTE: http://​stackoverflow.com/questions/12009/piping-password-to-smbpasswd 6 down vote​  If you have a blank SMB password (specified by the string "NO PASSWORD" in the smbpasswd file) then just press the <Enter> key when asked for your old password. smbpasswd can also be used by a normal user to change their SMB password on remote machines, such as Windows NT Primary Domain Controllers.

This unfortunately is not desirable for two reasons: 1) if the user uses a combination of '\n' in the password there will be a mismatch in the input 2) if there are unix users on the system, then a user using the utility ps may see the password

A better way would be to put the names in a file and read from the file and use python pexpect to read them, not like below, but the simple script is enough to see how to use pexpect

#!/usr/bin/python
#converted from: http://pexpect.sourceforge.net/pexpect.html
#child = pexpect.spawn('scp foo myname@host.example.com:.')
#child.expect ('Password:')
#child.sendline (mypassword)
import pexpect
import sys
user=sys.argv[1]
passwd=sys.argv[2]
child = pexpect.spawn('/usr/bin/smbpasswd -a '+str(user))
child.expect('New SMB password:')
child.sendline (passwd)
child.expect ('Retype new SMB password:')
child.sendline (passwd)

then try: ./smbpasswd.py userName1 'f#@(&*(_\n895'

Trouble piping with os.system() and smbpasswd : learnpython, When you run that script, it asks for a password, encrypts it, the user add for the and it works as I expect, just like BASH, but when piping to smbpasswd, it fails. Mark's answer implies that smbpasswd is expecting an old password and a new one, but this answer implies that smbpasswd is expecting a password and a password confirmation. The second interpretation is the correct one, and so I feel Mark's answer is less helpful than this one.

pdbedit for creating samba users · Issue #35 · saltstack-formulas , users instead of always piping the password to smbpasswd on every run. Additionally it would allow us to only store a password hash in the . Note: Questions MUST be programming related. Use this tag only if your question relates to development on Debian using operating system API's or Debian-specific features, or to creating packages in the deb format.

Setting Samba passwords using Chef without storing plain text , We tried setting the password backend to smbpasswd, and piping /etc/shadow through mksmbpasswd, but all that gave us was this garbage: How can I pipe the new password to smbpasswd so I can automate my installation process.… .net - Creating temporary folders I am working on a program that needs to create a multiple temporary folders for the application.

Smbpasswd failed to change password, Piping password to smbpasswd. Ask Question 26. 6. the approach beginning with a paren failed because Puppet couldn't find the command (echo . Thank you! smbpasswd -s. The -s option causes smbpasswd to be silent (i.e. not issue prompts) and to read its old and new passwords from standard input, rather than from /dev/tty (like the passwd(1) program does). This option is to aid people writing scripts to drive smbpasswd. id -u -n. id displays the system identifications of a specified user.

Comments
  • -1 This is exactly the answer of Mark, just changing variable names.
  • +1 to offset JorgeeFG; I think that the new variable names contain a distinction, if you read closely. Mark's answer implies that smbpasswd is expecting an old password and a new one, but this answer implies that smbpasswd is expecting a password and a password confirmation. The second interpretation is the correct one, and so I feel Mark's answer is less helpful than this one.
  • or echo -ne "$PASS\n" | tee - | smbpasswd -a -s $LOGIN?
  • smbpasswd’s -s stands for "use stdin for password prompt", not "silent"
  • @Michael according to samba.org/samba/docs/man/manpages/smbpasswd.8.html it means both "silent" (no prompts) and "read from stdin" (instead of /dev/ptty)
  • thanks, fwiw that's the only syntax I could get working in a Dockerfile: RUN PASS=myrootpassword ; echo ${PASS} | tee - | smbpasswd -a -s
  • I also found this answer useful as the only syntax I could get working in a Puppet exec resource; the approach beginning with a paren failed because Puppet couldn't find the command "(echo". Thank you!
  • This simply doesn't answer the question.