I have a very long bash script, at the end of it is a command to execute sudo commands on a remote server:
10 hours of local processing … ssh user@ip "sudo ls"
I have set up ssh keys to connect to the server and it's working, but it's not enough to run sudo commands. Also because this command is at the end of my script, I don't want to wait for an interactive prompt for the sudo password. Ideally, I would like a prompt for my password at the beginning of the script, store this password in a variable and then pass this variable in my ssh command to execute sudo commands on the remote server.
This is where I'm stuck. I have read countless posts about that but half of them suggest to use this:
ssh $HOST 'echo $PASSWORD | sudo -S $COMMMAND'
which is dangerous since it exposes my password, and half of them suggest to disallow the need for a password for sudo commands on the remote server.
Are these really the only two solutions?