While developing a shell script to copy logs from lots of remote servers, I found out a problem that I need to pass a password for each ssh connection to each server (and it makes me very nervous:) ). I know that it is better to use keys, but the process of adding them will take a lot of time due to our admins. As an option I found that it is possible to use the expect command, but it is not installed on our servers, and installation will take also a lot of time.
So, is it possible to simulate expect command behavior via plain shell scripts to pass passwords to ssh non-interactively?
If you have access to a compiler, you should be able to compile
expectfrom source. Ifexpectis difficult to compile, try empty, it’s a very small and simple program – if anything compiles, it should, too. Here is an example of using it to automate ssh login.Do note that others are right: ssh keys are your friends, while both
expectandemptyare usually just ugly and unsafe workarounds.