LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   ssh to Server from within a Shell Script (https://www.linuxquestions.org/questions/linux-server-73/ssh-to-server-from-within-a-shell-script-873331/)

devUnix 04-06-2011 08:07 AM

ssh to Server from within a Shell Script
 
Hi!


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

Hello,

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,

Eric

devUnix 04-06-2011 01:51 PM

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

http://www.linuxquestions.org/questi...nd-ntp-873325/

EricTRA 04-06-2011 02:22 PM

Hi,

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

Kind regards,

Eric


All times are GMT -5. The time now is 09:40 AM.