2

This question already has an answer here:

I want to create a file like this : sshTOhost :

#!bin/bash
ssh -D 1500 user@host
#enter password (I don't know how)

marked as duplicate by slm, manatwork, Drav Sloan, Mat, Anthon Sep 21 '13 at 15:39

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.

5

You can use sshpass to use ssh in a shell script; the script can then automatically provide the password to ssh by using sshpass. The linked article explains how to do this, and also why you absolutely shouldn't do this.

Instead, you should use public key authentication. If you need to automate it completely without any user input, you can set up a private key without passphrase; your script can then use this key to connect to the remote host without any user input.

2

You have another way:

expect is a command line for your task, at first install it, Then write in your script:

#!bin/bash
ssh -D 1500 user@host
expect "Echo of after ssh -D 1500 user@host"
send yourpassword\r
wait

Of course, It's dangerouse, because everyone can read your password.

0

I use expect in a script to automate the installation of software on new servers. It has a bit of a learning curve but once it is set up, it works really well.

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