How login in a shell script to many Linux systems from one main Linux machine, without password in configuration?
Asked
Active
Viewed 331 times
0
-
1What method are you using to connect from the first machine to the others? `telnet`? `ssh`? Something else? – Tripp Kinetics Apr 12 '18 at 15:37
-
Is it possible with telnet or ssh without passwordless ssh configuration. – Ramesh Das Apr 12 '18 at 15:43
-
I don't think you want "less" in your sentences. – pawamoy Apr 12 '18 at 15:44
-
Yes that is correct without password. – Ramesh Das Apr 12 '18 at 15:48
-
If the aim is to automate running commands on multiple machines then there are good tools for doing that. See the answer by @damienfrancois to [bash script parallel ssh remote command](https://stackoverflow.com/q/26338438/4154375) for a useful list. I've found that Ansible works well, with or without passwords. – pjh Apr 13 '18 at 11:00
2 Answers
0
Literally from your question, you do not want a passwordless connection between hosts. In this case, you will need to enter passwords N times. Also, there is no context about the type of connection and commands you need to run. Then, a simple one-liner shell example could be the following: for i in {"user1@host1","user2@host2"}; do ssh $i "hostname &"; done
However, why would you avoid a passwordless connection?
Richard
- 11
- 1
-
Is there any way to do this kind of setup with help of shell script because in your solution it will ask for password every time if the password different. So its helpful but can we do avoiding passwordless setup. – Ramesh Das Apr 12 '18 at 16:08
-
Considering that you will connect to multiple machines with the same password then. You could provide the password in the script, but this is strongly not recommended. Either check SSH's manual or check [here](https://stackoverflow.com/questions/12202587/automatically-enter-ssh-password-with-script) for providing password with ssh command. – Richard Apr 12 '18 at 16:13
-
0
Any (most?) interactive methods of login can be scripted by using expect. Your expect script will wait for the password prompt and then provide the password. You will have read the password from a file or defined it as a variable in the script.
Tripp Kinetics
- 5,178
- 2
- 23
- 37
-
'sshpass' may be an easier option if passwordless is not possible. See [Automatically enter SSH password with script](https://stackoverflow.com/q/12202587/4154375). – pjh Apr 13 '18 at 11:06