0

I want to execute commands on a remote machine. The remote user requires password authentication. I am getting following error when using the below sample script, This is the content of sample script applmgr.sh

#!/bin/bash    
ssh applmgr@192.168.1.30 -c "cd ; touch testing ; cp testing testing_is ;mv testing 
working" <<!
applmgr      ## Password of applmgr user##
!

When executed, it gives below message,

[oracle@dbsrvr ~]$ sh applmgr.sh
standard in must be a tty
3

Putting your passwords into scripts is a very bad security practice. But if you must do so for Reasons, you can use a tool such as sshpass for this purpose.

I suggest strongly, however, that you look into using key pair authentication for jobs such as these.

If you are on host a.example.com and you have jobs to run on b.example.com, you can set yourself up to do so with the following commands:

  • ssh-keygen - This will create a public/private keypair to be used for authentication
  • ssh-copy-id username@b.example.com - This will set your public key up on the remote host for use. You'll be asked for your password when you run this command, but thenceforth the keys will be used to authenticate.

From that point onward, you can use e. g. ssh username@b.example.com 'command' to run command on the remote host.

0

Have a look at the expect command, this is the system built to interact with applications and simulate user behavior.

(but of course ditching passwords in favor of keys is the true solution)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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