English 中文(简体)
How do you change a user password in a script with busybox and openssl?
原标题:

I need to synchronize a user account and password to an external source on a system with busybox and openssl installed. When the external source tells my system to update credentials, how do I change the user s password in a script? I will have the password in plain text.

This has to be automated, and from what I can tell busybox passwd is interactive and I don t particularly want to write an expect-type script for passwd if that s even possible. It looks like openssl can generate password hashes (openssl passwd -1 -salt "abcdefgh" {password}), but will I have to modify /etc/shadow directly?

Busybox has these commands available.

最佳回答

You can write a small script like this to update the password. Put the following text in a file and execute it. It will change your password.

#!/bin/sh
passwd << EOF
<old password>
<new password>
<new password>
EOF

问题回答

Turns out current versions of busybox have chpasswd (source code). chpasswd takes a colon-delimited pair username:password on stdin. I don t know whether I can update the busybox on my system, but I ll leave this answer in case someone else comes looking.

From the busybox documentation:

chpasswd
chpasswd [--md5|--encrypted]

Read user:password from stdin and update /etc/passwd

Options:

        -e,--encrypted  Supplied passwords are in encrypted form
        -m,--md5        Use MD5 encryption instead of DES




相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

热门标签