I'm attempting to migrate an OpenVPN server from a CentOS box to an Ubuntu 18.04 one.
There is a script which creates new VPN users. Part of this is that it generates a new password for the user and then passes this in as the Linux password for the new user (there is MFA on top of this so this is only one part of the authentication process).
However the script uses the following line to do this:
echo ${VPN_PASSWORD} | passwd "${VPN_USER}" --stdin
And after messing around for a long time I've discovered that Ubuntu doesn't have the --stdin
option for passwd
.
What I haven't been able to find, however, is an alternative way of doing this.
These are the relevant parts of my script.
We generate a password:
VPN_PASSWORD=$(cat /dev/urandom | tr -dc 'A-Z0-9' | head -c 8)
We add a new user and attempt to assign this password to it:
echo "Adding Unix user ${VPN_USER}"
useradd -G vpnusers -m -s /sbin/nologin $VPN_USER
if [ "$?" != 0 ]
then
echo "Could not create user. (Are you sudo?!)"
exit 1
fi
echo ${VPN_PASSWORD} | passwd "${VPN_USER}" --stdin
echo "User created."
The user is being created but I'm getting this error regarding the password:
passwd: unrecognized option '--stdin'
Usage: passwd [options] [LOGIN]
I've been trying for a day to find and answer to this and tried many, many things but I think my fundamental lack of Ubuntu knowledge is the real issue here.
To set a user's password from the shell use
chpasswd
: