Faced with the need to launch an ssh session with another PC within a script.
I found 3 solutions for myself
Method 1
This method is not safe at all, and with complex passwords, you need to play around with escaping
ssh user@host bash -c "echo mypass | sudo -S mycommand"
Method 2
Also unsafe, but better handles complex passwords
Install the sshpass utility
apt-get install sshpass sshpass -p 'password' ssh username@server
Method 3
Create an ssh key and log in using it
ssh-keygen
And press enter several times
Next, you need to copy the key to the server
ssh-copy-id user@ip
Enter the password and everything is ready. We can try to log in without a password
ssh user@ip