Discussion:
Change root password from shell-script
(too old to reply)
Jordi Espasa Clofent
2010-01-27 16:05:17 UTC
Permalink
HI all,

?Is there any way t change the root password using a shell-script (aka
non-interactive mod as passwd uses)?

I've used pw in FreeBSD and chpasswd in Debian GNU/Linux to do it, bit
I've not found a way/command to do it with my OpenBSD boxes.

At present my approach will be install except from ports and use it to
get my goal.
--
I must not fear. Fear is the mind-killer. Fear is the little-death that
brings total obliteration. I will face my fear. I will permit it to pass
over me and through me. And when it has gone past I will turn the inner
eye to see its path. Where the fear has gone there will be nothing. Only
I will remain.

Bene Gesserit Litany Against Fear.
Gregory Edigarov
2010-01-27 16:18:14 UTC
Permalink
On Wed, 27 Jan 2010 17:05:17 +0100
Post by Jordi Espasa Clofent
HI all,
?Is there any way t change the root password using a shell-script
(aka non-interactive mod as passwd uses)?
I've used pw in FreeBSD and chpasswd in Debian GNU/Linux to do it,
bit I've not found a way/command to do it with my OpenBSD boxes.
At present my approach will be install except from ports and use it
to get my goal.
Have you looked at man usermod? -p flag in particular.
--
With best regards,
Gregory Edigarov
Jordi Espasa Clofent
2010-01-27 16:48:15 UTC
Permalink
Post by Gregory Edigarov
Have you looked at man usermod? -p flag in particular.
Shame on me, indeed. It has been a game:

#!/bin/sh
PASSWORD=$(echo "my_new_password" | encrypt -b 6)
usermod -p $PASSWORD root

Thanks.
--
I must not fear. Fear is the mind-killer. Fear is the little-death that
brings total obliteration. I will face my fear. I will permit it to pass
over me and through me. And when it has gone past I will turn the inner
eye to see its path. Where the fear has gone there will be nothing. Only
I will remain.

Bene Gesserit Litany Against Fear.
Paul Branston
2010-01-27 17:14:51 UTC
Permalink
Post by Jordi Espasa Clofent
Post by Gregory Edigarov
Have you looked at man usermod? -p flag in particular.
#!/bin/sh
PASSWORD=$(echo "my_new_password" | encrypt -b 6)
usermod -p $PASSWORD root
A little more generic in case there is no usermod -p

PASSWORD=$(echo "my_new_password" | encrypt -b 6)
perl -p -i.bk -e 's/^root:.*?:/root:$PASSWORD:/' /etc/shadow
Brynet
2010-01-27 17:45:31 UTC
Permalink
Post by Paul Branston
A little more generic in case there is no usermod -p
PASSWORD=$(echo "my_new_password" | encrypt -b 6)
perl -p -i.bk -e 's/^root:.*?:/root:$PASSWORD:/' /etc/shadow
Wow,

Question: are you even using OpenBSD?

-Bryan.
Chris Dukes
2010-01-27 19:43:59 UTC
Permalink
Post by Paul Branston
Post by Jordi Espasa Clofent
Post by Gregory Edigarov
Have you looked at man usermod? -p flag in particular.
#!/bin/sh
PASSWORD=$(echo "my_new_password" | encrypt -b 6)
usermod -p $PASSWORD root
A little more generic in case there is no usermod -p
PASSWORD=$(echo "my_new_password" | encrypt -b 6)
perl -p -i.bk -e 's/^root:.*?:/root:$PASSWORD:/' /etc/shadow
Breaks on AIX :-). Breaks with NIS and LDAP as well :-).

I've always had the pipe dream of there being a chpasswd(8)
on *BSD like there is on current AIX and Linux distros.
But usually there isn't that much headache using something like usermod.
--
Chris Dukes
Julian Leyh
2010-01-28 12:48:45 UTC
Permalink
Post by Paul Branston
A little more generic in case there is no usermod -p
PASSWORD=$(echo "my_new_password" | encrypt -b 6)
perl -p -i.bk -e 's/^root:.*?:/root:$PASSWORD:/' /etc/shadow
/etc/shadow: no such file

Continue reading on narkive:
Loading...