title: Change Unix password from command line over Python/Fabric
body: <p>I would like a way to update my password on a remote <code>Ubuntu 10.4</code> box with <a href="http://docs.fabfile.org/0.9.1/index.html" rel="noreferrer">fabric</a>.</p>
  
  <p>I would expect my <code>fabfile.py</code> would look something like this:</p>
  
  <pre><code>def update_password(old_pw, new_pw):
      # Connects over ssh with a public key authentication
      run("some_passwd_cmd --old %s --new %s" % (old_pw, new_pd))
  </code></pre>
  
  <p>Unfortunately the only command I know of that lets one change the password is <code>passwd</code>, and on Ubuntu 10.4 there doesn't seem to be any way to pass in the new (or old) password as an argument to <code>passwd</code>.</p>
  
  <p>What command could one use to change a user's password on Ubuntu 10.4 via <code>fabric</code>?</p>
  
  <p><strong>EDIT</strong>:
  I've had a look at <code>usermod -p</code>, and that may work but it isn't recommended by the man page.</p>
  
  <p><strong>EDIT</strong>: For some reason <code>usermod -p</code> wasn't working either over fabric.</p>
  
  <p>As well, I've tried a (somewhat insecure) variation on mikej's answer that did solve the problem:</p>
  
  <pre><code># connecting &amp; running as root.
  from fabric.api import *
  from fabric.contrib import files
  
  files.append("%s\n%s" % (passwd, passwd), '.pw.tmp')
  # .pw.tmp:
  # PASSWD
  # PASSWD
  
  run("passwd %s &lt; .pw.tmp" % user)
  
  run("rm .pw.tmp")
  </code></pre>
  
  <p>It's not a very elegant solution, but it works.</p>
  
  <p>Thank you for reading.</p>
  
  <p>Brian</p>