Piping password to smbpasswd

后端 未结 7 1066
庸人自扰
庸人自扰 2020-12-25 12:52

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

7条回答
  •  眼角桃花
    2020-12-25 13:22

    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'

提交回复
热议问题