How to change a Linux user password from python

后端 未结 6 857
心在旅途
心在旅途 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:47

    The user you are running this as must have sudo permission to run the passwd command without a password.

    >>> from subprocess import Popen
    >>> proc = Popen(['/usr/bin/sudo', '/usr/bin/passwd', 'test', '--stdin'])
    >>> proc.communicate('newpassword')
    

提交回复
热议问题