Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am in server 1. I need to remotely login to server 2 from server 1. Now from server 2 I will run a script that will scp some file to server3.

I need to write a script in server 1 that will will automatically remote login from server 1 i.e. it reads password of user@server2 from some file or i can echo password in ssh command. and then it runs the the script in server 2 automatically without any user interference of running it.the automation of scp of server 2 to server 3 has been done in the script that is in server 2. I just need the automation of above mentioned query.

Without using expect or ssh-keygen

share|improve this question

closed as off-topic by Braiam, Radu Rădeanu, Eric Carvalho, mikewhatever, Avinash Raj Apr 18 '14 at 2:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Braiam, Radu Rădeanu, Eric Carvalho, mikewhatever, Avinash Raj
If this question can be reworded to fit the rules in the help center, please edit the question.

dublicate: – Takkat Feb 11 '11 at 11:10
You can not achieve interactive automation without using an expect alike tool. I was able to implement exactly what you are asking for using python pexpect, unfortunately I can't publish it. – João Pinto Feb 11 '11 at 13:49

By using ssh and scp you can use key based authentication instead of passwords. Then you can make this "automated" without user interaction which would be the case with password authentication. Some hits about this topic with google:

You mentioned "without ssh-keygen". What's your problem with it? If you don't use keys how you want to avoid using passwords, which is your problem, if I understand your issue.

share|improve this answer
i want to read the password of remote server from a file....something like this-- cat /tmp/pass_file | ssh -l localuser remote user script_to_be_executed...there are so many servers, i need to remotely login again and again – user10631 Feb 11 '11 at 11:42
What you want is really dangerous. So you must keep passwords somewhere as plain text. Personally I think this should be never ever be done! In system passwords file (like /etc/shadow), passwords are always encrypted, it's never a good idea to store passwords as clear-text ones. But anyway, I still can't understand what's the problem with key based login for you (please tell), you can do the same with it (ssh/scp again and again) and you don't need interaction from the user (enter passwd) so the same result, but much more secure, and much more "standard, good thing to do" feeling. – LGB Feb 11 '11 at 12:40
Btw, if your problem is that, you can use multiple key pairs, and you can use the "-i" switch of ssh to tell what (private) key file you want to use. Then you can issue a command like this: "ssh -i key_for_this_server user@remote ./script" for example, and the ./script will run on the remote machine without the need you enter password, or anything (for sure, with the some pre-work to install the - public - key on the remote machine, but it must be done only once). You can even redirect the output (stdout) so you can store the output of locally run script, etc etc. – LGB Feb 11 '11 at 12:57
And for sure, nobody told that you have to have different key pairs for all systems, though maybe it's a good idea. But even with only one key pair, it's still far better than using/storing clear text passwords. – LGB Feb 11 '11 at 13:17
Strong +1 for key-based auth. I can't understand why OP resist it. – ulidtko Feb 11 '11 at 16:28