How can I set a users password in linux from a python script?

后端 未结 5 1779
陌清茗
陌清茗 2020-12-09 00:54

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:



        
5条回答
  •  盖世英雄少女心
    2020-12-09 01:16

    You forgot this:

    stdin=subprocess.PIPE
    

    To send data to the process, you need a stdin.

    So the full statement is:

    process = subprocess.Popen(['sudo', 'chpasswd'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
    

    and then call communicate('password').

提交回复
热议问题