This question already has an answer here:

I want to ssh to remote machine within shell script but remote machine require password. How should i provide password in my script?

I tried below but its not working. Please suggest

SSH <hostname>

marked as duplicate by Jenny D, roaima, slm Mar 17 '16 at 11:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    Don't. Instead, use a passwordless SSH key with limited permissions. – Jenny D Mar 17 '16 at 10:42

I suggest to use a ssk-key so you do not have to provide any password. There are plenty of tutorials out there on how to use them, for example this one.

In case you want to use inline password you can try installing sshpass and executing:

sshpass -p 'YourPassword' ssh user@host

Source: SSH login with clear text password as a parameter?

By the way, if you want to execute a command in the remote machine, you just have to write the remote command between quotation marks:

sshpass -p 'YourPassword' ssh user@host "ls -l"

Not the answer you're looking for? Browse other questions tagged or ask your own question.