0

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

#!/bin/bash
SSH <hostname>
<password>
1
  • 3
    Don't. Instead, use a passwordless SSH key with limited permissions.
    – Jenny D
    Mar 17 '16 at 10:42
1

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.