How to change a Linux user password from python

后端 未结 6 997
心在旅途
心在旅途 2021-01-03 08:23

I\'m having problems with changing a Linux user\'s password from python. I\'ve tried so many things, but I couldn\'t manage to solve the issue, here is the sample of things

6条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-03 08:44

    For those that --stdin isn't an option:

    import subprocess
    cmd = "bash -c \"echo -e 'NewPassword\\nNewPassword' | passwd root\""
    subprocess.check_call(cmd, shell=True)
    

提交回复
热议问题