su: Authentication token manipulation error
by hacback17 from LinuxQuestions.org on (#4Z4ZG)
Hi everyone,
The code snippet works fine (that means it creates a user, sets a password) but when I try to login as the recently created user, it produces "su: Authentication token manipulation error" error. Please help me understand what's wrong.
Code:#!/bin/bash
# This script creates a new user on the local system.
# You will be prompted to enter the username (login), the person name, and a password.
# The username, password, and host for the account will be displayed.
# Make sure the script is being executed with superuser privileges.
if [[ "${UID}" -ne 0 ]]
then
echo 'Please run with sudo or as root.'
exit 1
fi
# Get the username (login).
read -p 'Enter the username to create: ' USER_NAME
# Get the real name (contents for the description field).
read -p 'Enter the name of the person or application that will be using this account: ' COMMENT
# Get the password.
read -p 'Enter the password to use for the account : ' PASSWORD
# Create the account.
useradd -c "${COMMENT}" -m ${USER_NAME}
# Check to seeif the useradd command succeded.
# We don't want to tell the user that an account was created when it hasn't been.
if [[ "${?}" -ne 0 ]]
then
echo 'The account could not be created.'
exit 1
fi
# Set the password
echo ${PASSWORD} | passwd --stdin ${USER_NAME}
if [[ "${?}" -ne 0 ]]
then
echo 'The password for the account could not be set.'
exit 1
fi
# Force password change on first login.
passwd -e ${USER_NAME}
# Display the username, password, and the host where the user was created.
echo #blank line
echo 'username:'
echo "${USER_NAME}"
echo
echo 'password:'
echo "${PASSWORD}"
echo
echo 'host:'
echo "${HOSTNAME}"
exit 0


The code snippet works fine (that means it creates a user, sets a password) but when I try to login as the recently created user, it produces "su: Authentication token manipulation error" error. Please help me understand what's wrong.
Code:#!/bin/bash
# This script creates a new user on the local system.
# You will be prompted to enter the username (login), the person name, and a password.
# The username, password, and host for the account will be displayed.
# Make sure the script is being executed with superuser privileges.
if [[ "${UID}" -ne 0 ]]
then
echo 'Please run with sudo or as root.'
exit 1
fi
# Get the username (login).
read -p 'Enter the username to create: ' USER_NAME
# Get the real name (contents for the description field).
read -p 'Enter the name of the person or application that will be using this account: ' COMMENT
# Get the password.
read -p 'Enter the password to use for the account : ' PASSWORD
# Create the account.
useradd -c "${COMMENT}" -m ${USER_NAME}
# Check to seeif the useradd command succeded.
# We don't want to tell the user that an account was created when it hasn't been.
if [[ "${?}" -ne 0 ]]
then
echo 'The account could not be created.'
exit 1
fi
# Set the password
echo ${PASSWORD} | passwd --stdin ${USER_NAME}
if [[ "${?}" -ne 0 ]]
then
echo 'The password for the account could not be set.'
exit 1
fi
# Force password change on first login.
passwd -e ${USER_NAME}
# Display the username, password, and the host where the user was created.
echo #blank line
echo 'username:'
echo "${USER_NAME}"
echo
echo 'password:'
echo "${PASSWORD}"
echo
echo 'host:'
echo "${HOSTNAME}"
exit 0