Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
dublicate: superuser.com/q/244478 –  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
add comment

1 Answer

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
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.