skip to Main Content

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


  1. In the manpages, there is the following:

    Finally, if other authentication methods fail, ssh prompts the
    user for a password. The password is sent to the remote host for
    checking; however, since all communications are encrypted, the
    password cannot be seen by someone listening on the network.

    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 the ssh command.

    Login or Signup to reply.
  2. I’ve never encountered such scenario but try using sshpass -p <password> ssh <username>@<ip-address> at the beginning and see if it helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search