0

I'm new to Bash and I'm doing a for loop in a script which will ssh onto various servers (all have the same username and password) but is there a way I can bypass the password prompt to save time?

Hopefully someone can help!

NW_92
  • 119
  • 1
  • 1
  • 5
  • https://www.tecmint.com/sshpass-non-interactive-ssh-login-shell-script-ssh-password/ – Abelisto Apr 03 '20 at 11:25
  • Does this answer your question? [How to get a password from a shell script without echoing](https://stackoverflow.com/questions/3980668/how-to-get-a-password-from-a-shell-script-without-echoing) – KamilCuk Apr 03 '20 at 11:26
  • Also you might interest yourself in ansible, puppet and ssh-copy-id. – KamilCuk Apr 03 '20 at 11:26
  • @KamilCuk again, you misunderstood the question. This is probably a duplicate (asking for sshpass or sth like that) but not of the one you linked – oguz ismail Apr 03 '20 at 11:30

1 Answers1

2

Password authentication is inferior to public-key authentication security-wise. While you could achieve what you want with sshpass, I recommend switching to public key authentication and employ ssh-agent(1) to not reenter passphrases everytime.

Here's how you would setup ssh-agent:

In ~/.ssh/config for each server entry add ForwardAgent yes field, or if you want to do it globally, just add

Host *
    ForwardAgent yes

Then employ the ssh-agent(1) like this:

$ eval `ssh-agent`
$ ssh-add /home/test/.ssh/id_rsa_1
$ ssh-add /home/test/.ssh/id_rsa_2
vtronko
  • 478
  • 3
  • 10