I\'m trying to automate the setup of SFTP access. This script is running as a user with sudo permissions and no password.
I can create a user like so:
Try below code which will do as you required automation
from subprocess import Popen, PIPE, check_call
check_call(['useradd', 'test'])
proc=Popen(['passwd', 'test'],stdin=PIPE,stdout=PIPE,stderr=PIPE)
proc.stdin.write('password\n')
proc.stdin.write('password')
proc.stdin.flush()
stdout,stderr = proc.communicate()
print stdout
print stderr
print statements are optional.