I am new to linux and I am trying to create user across many servers and I use ssh for it.
ssh -t adm@"$SERVER" /bin/sh << EOF
# Check if user already exists
if id "$USERNAME" >/dev/null 2>&1; then
echo "User $USERNAME already exists on $SERVER."
else
# Create user on the remote server
sudo -S useradd -m -s /bin/bash "$USERNAME"
fi
EOF
while executing this, my prompt is not asking for the adm password and it fails. Please see logs
sudo: no password was provided
sudo: a password is required
What should I do so that the prompt asks me the password of adm and uses it to create a user ?
2
Answers
In the manpages, there is the following:
As you see,
ssh
is set up in such a way that entering the password does not reveal the password, which would not make much sense if the password is given along with thessh
command.I’ve never encountered such scenario but try using
sshpass -p <password> ssh <username>@<ip-address>
at the beginning and see if it helps.