Shell script- prompt user for password, save in variable and call that variable when promoted for ssh password
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

I have script to ssh to multiple server one at a time. The only problem is it keeps asking for password everytime i ssh. The solution im after is that when i ssh to that server the variable will be provided as password. Note that cannot install sshpas.

awarded to kerncy

Crowdsource coding tasks.

2 Solutions

Winning solution


You may use SSH without password by generating a key/pair for each server you want to connect. After that, you won't be asked for a password :

It's much better than storing the password in "clear" mode.

Hi kerncy, i will try this first and award you the bounty once it is confirmed. I'm just hoping sshkey gen is not disabled on my user ids. I'm not the admin/root/sudo user. Just to confirm, do i need to generate the key on the jump server on every remote servers i have? Like i have 20 servers or i can copy the same key to all?this is also per user right? other user on the server need to set up their own sshkeys?
Newbiebounty 6 months ago
Hello, thank you for the award. I'm a bit late to answer your questions, but you will have to generate the keys on each server (you can't use the same I think, and it's better for security reason). You also have to generate a key per user.
kerncy 6 months ago

I use the following command:

sshpass -p "YOURPASSWORD" ssh

And I have created an alias:

alias connect='sshpass -p "YOURPASSWORD" ssh'

So on my terminal I do:

$ connect

...whenever I want quick access

Actually, i dont think i can use sshpas as it not installed by default and i cannot use yum.Also, i created a shell script menu driven as i have 20+ servers. If you can advise other than the sshkey gen, will weigh it against the sshkey answer
Newbiebounty 6 months ago
"i cannot use yum" - it sounds like that's the first problem you should solve.
slang 6 months ago
View Timeline