0

I want to write one shell script like

command1    
ssh vivek@remotehost 
    fire command on remote host

Now I have password in pass.txt . But when I change stdin with file. It is not reading password from file.

script.sh < password.txt 

It is prompting for the password in place of reading password from the file. What I am doing wrong ?

Second problem is that shell script don't shows the command fired. Is there a way , I can show fired command from it ?

Note : I don't have key based access on remote system. I can only use password based login for ssh.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Vivek Goel
  • 22,942
  • 29
  • 114
  • 186
  • Do you have remote ssh server deliberately set up to *deny* key-based authorization, or you can't write to $HOME/.ssh directory? That's the only 2 ways I can think of why you can't use keys... – GreyCat Jun 01 '11 at 07:05
  • I don't have permission to write in $HOME/.ssh . – Vivek Goel Jun 01 '11 at 09:06
  • possible duplicate of [Way to automatically enter in shell password?](http://stackoverflow.com/questions/8200461/way-to-automatically-enter-in-shell-password) – Aaron Digulla Oct 03 '13 at 14:55

3 Answers3

2

You can use ssh-agent or expect (the programing language) to do this.

Joshua Smith
  • 6,561
  • 1
  • 30
  • 28
1

OpenSSH ssh does not reads the password from stdin but from /dev/tty. That's why you have to use Expect or some other similar tool to automate it.

plink is another client, also available for Linux/Unix that accepts the password as a parameter on the command line... though that has some ugly security implications.

salva
  • 9,943
  • 4
  • 29
  • 57
1

Okay, just to mention yet another option: sshpass is a tool developed for exactly the task of "fooling" regular openssh client to accept password non-interactively.

GreyCat
  • 16,622
  • 18
  • 74
  • 112