chpasswd in Stackscript

What I'm trying to do:

echo "myusername:$password" | chpasswd

What I see in the log:

chpasswd: (user minecraft) pam_chauthtok() failed, error:
Authentication token manipulation error
chpasswd: (line 1, user minecraft) password not changed

I've tried all kinds of strategies for this. I originally thought could do something like:

echo -e "$password\n$password" | (passwd myusername)

which I've read on a lot of forums is the way to go, but I get token manipulation errors for that too.

Surely I'm not the only person who tries to set the password for a particular user in a Stackscript. Any idea what I'm doing wrong?

2 Replies

There are two factors at play here. The first is that chpasswd is normally used to update passwords in a batch, whereas sudo passwd $user is normally used to change an individual user account. Since this is a Stackscript, there may not be a way around this. However, feeding the information directly into /etc/shadow may be a better option than using chpasswd.

Typically an "authentication token manipulation error" is caused by a permissions issue. This permissions error can be in either the filesystem or /etc/shadow.


If the filesystem is mounted as read-only, you won't be able to change the user password. In this case you would need to remount the filesystem using sudo mount -o remount,rw /.


Incorrect permissions on this file can also cause errors with changing a user password. You can check permissions on /etc/shadow using ls -l /etc/shadow. The permissions should be 640; if they are not, change them using sudo chmod 640 /etc/shadow.

There are some less common errors that may be occurring; more information can be found in this article. Additional troubleshooting may involve using fsck or freeing up disk space.

I learned from a quick Google search that the most common cause of that error is that the filesystem is mounted read-only, but I'm skeptical that this is the problem here for two reasons. Firstly, it's a Stackscript, the very purpose of which is to tinker with a newly-minted Linode. And more to the point, the adduser command is successful. I originally tried to set the password in the adduser but got a token manipulation error from that too, so I thought maybe I could add the user and then set the password. Now the adduser works, but setting the password doesn't. All the other stuff my Stackscript does when I deploy a Linode--including downloading some files I have stored elsewhere--works. It just won't set the password.

I can't shake the feeling that I'm overlooking something simple that SHOULD be obvious to me.


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct