This question already has an answer here:

I want to create a file like this : sshTOhost :

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.


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.


You have another way:

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

ssh -D 1500 user@host
expect "Echo of after ssh -D 1500 user@host"
send yourpassword\r

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


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.