I am trying to add a user account to my remote server (running on Ubuntu 22.04) via SSH using below script:
#!/bin/bash
protect="y"
ssh -i ssh_key root@server.ip <<END
sudo deluser testuser
if [[ "$protect" =~ ^[yY]*$ ]]; then sudo useradd -p $(openssl passwd -1 "password") testuser && echo "User added successfully"; fi
END
read -n 1 -srp "Press any key to exit."
The confirmation message User added successfully
is showing and the user is added normally. Except I can't login to that account with these credentials.
When I try to execute these commands one by one directly on the server, everything works fine and I can login to that account, so I assumed it would be some quotes escaping issue, and I tried some variantes including:
\""password"\"
"\"password"\"
\""password\""
"\"password\""
But none worked.
Please help me.