-   Linux - Server (
-   -   ssh to Server from within a Shell Script (

devUnix 04-06-2011 08:07 AM

ssh to Server from within a Shell Script

How do we ssh to a server from within a Shell Script (Bash)?

I have been trying to achieve it but it seems that ssh does not support stdin for password.

I want to ssh to a particular server and execute some commands/scripts and then logout of it. I want to do it all from within a Shell Script so that I can add it to crontab.

Any ideas?

EricTRA 04-06-2011 08:17 AM


The best and most secure way would be to set up key authentication to that remote server so that you don't have to provide a password. If you cannot (or don't want to) go that way (which is the most secure) you could use a tool like sshpass that can be used to pass on your password to ssh from within a script. Using sshpass your password will be visible in the script so limit access to the file/computer you're using it on or encrypt your script when you've found it functional.

Kind regards,


devUnix 04-06-2011 01:51 PM

The problem is resolved and is related to my other thread:

EricTRA 04-06-2011 02:22 PM


Glad you've got it solved and that you choose to use key authentication as a solution. Have fun with Linux.

Kind regards,


All times are GMT -5. The time now is 03:08 PM.